Inserting a New Row Into UD01 From a Customization Through an Adapter

I’m trying to insert a new row into UD01 from a customization through the UD01 adapter.

I just want to pass a User ID into Key1 and a Class ID into Key 2. I’ve had luck updating existing UD rows through the adapter, but I can’t figure out how to insert a new row.

I’ve searched, snipped, tested, traced, and explored objects fruitlessly, and I’m at the point where I’m just going to ask to see if I’m anywhere near the right track. This is the closest I’ve gotten:

		//Process this User and Part Class
		UD01Adapter adapterUD01 = new UD01Adapter(oTrans);
		adapterUD01.BOConnect();
					
		DataRow dr = adapterUD01.UD01Data.UD01.Rows.Add();

		dr.BeginEdit();
			dr["Company"] = "NOS";
			dr["Key1"] = thisUserID;
			dr["Key2"] = thisClassID;
			dr["Key3"] = "";
			dr["Key4"] = "";
			dr["Key5"] = "";
		dr.EndEdit();
		
		adapterUD01.Update();
		adapterUD01.Dispose();

This code compiles successfully, but when executed, I’m given the error “Column ‘Company’ does not allow nulls.”

Am I anywhere close to the mark here? Or is there another way to build the row for inserting into UD01?

Use adapterUD01.GetaNewUD01();

or look at

1 Like

Thank you! Here’s the working code for anyone looking in the future:

		//Process this User and Part Class
		UD01Adapter adapterUD01 = new UD01Adapter(oTrans);
		adapterUD01.BOConnect();

		var dr = adapterUD01.UD01Data.UD01.NewUD01Row();

		//Initialize everything (important!)
		for (int x = 1; x <= 20; x++)
        {
                   dr["CheckBox" + x.ToString("d2")] = false;
                   dr["Number" + x.ToString("d2")] = 0;
                   dr["ShortChar" + x.ToString("d2")] = "";
                   if(x<11) dr["Character" + x.ToString("d2")] = "";
                   dr["Date" + x.ToString("d2")] = DBNull.Value;
                   
        }

		//Initialize what's being used
		dr.BeginEdit();
			dr["Company"] = "NOS";
			dr["Key1"] = thisUserID;
			dr["Key2"] = thisClassID;
			dr["Key3"] = "";
			dr["Key4"] = "";
			dr["Key5"] = "";
		dr.EndEdit();
		
		adapterUD01.UD01Data.UD01.AddUD01Row(dr);

		adapterUD01.Update();
		adapterUD01.Dispose();
4 Likes