Update UD110A Child Table

Adam,

Do you get any rows when calling the adapter like that?

-Utah

I updated it to this and it popped the message of Record exists but it still didn’t update the correct record that matched the ChildKeys given. It just updated the first record that matched the keys for UD110. .
```
private void CallUD110AdapterGetByIDMethodDelete()
{
try
{
UD110Adapter adapterUD110 = new UD110Adapter(this.oTrans);
adapterUD110.BOConnect();
string Key1 = “PMOPERATIONS”;
string Key2 = tbFreqCodeBase.Text;
string Key3 = tbTypeCodeBase.Text;
string Key4 = tbEquipTypeID.Text;
string Key5 = string.Empty;
string childKey1 = “OPERINSTRUCT”;
string childKey2 = tbInstNum.Text;
string childKey3 = string.Empty;
string childKey4 = string.Empty;
string childKey5 = string.Empty;
bool result = adapterUD110.GetByID(Key1, Key2, Key3, Key4, Key5);
foreach(UltraGridRow dr in this.gridPMInstructions.Rows.GetRowEnumerator(GridRowType.DataRow, null, null))
{
bool shouldBreak = false;
for(int i = 0; i < adapterUD110.UD110Data.UD110A.Rows.Count; i++)
{
if(dr.GetCellValue(“UD110A_ChildKey1”).ToString() == childKey1 && dr.GetCellValue(“UD110A_ChildKey2”).ToString() == childKey2 && dr.GetCellValue(“UD110A_ChildKey3”).ToString() == childKey3 && dr.GetCellValue(“UD110A_ChildKey4”).ToString() == childKey4)
{
MessageBox.Show(“Record exists”);
bool checkstatus = true;
adapterUD110.UD110Data.UD110A[i].CheckBox01 = checkstatus;
adapterUD110.UD110Data.UD110A[i].RowMod = “U”;
adapterUD110.Update();
shouldBreak = true;;

		}
				if(shouldBreak)
				break;
			}
		}
	} catch (System.Exception ex)
	{
		ExceptionBox.Show(ex);
		MessageBox.Show("PMS Instruction wasn't updated");
	}
		}

I see what you are doing now… For the life of me I couldn’t understand the application of this code. You have a grid and you are going through the grid and looking for rows that match your keys, is that correct?

Shannon, is the grid bound to UD110A?

Yes, that is correct. It is bound to a DataView for UD110 and UD110A.

Will you please try this code and see if it works for you?

This code will loop through your data view that the grid is bound to if I am not mistaken.

Update the if statement with the rest of your keys. So && dr[“ChildKey2”] == childKey2.

EpiDataView ThisUD110A;

ThisUD110A = (EpiDataView)(this.oTrans.EpiDataViews[“UD110A”]);

string childKey1 = “test”;
string childKey2 = string.Empty;
string childKey3 = string.Empty;
string childKey4 = string.Empty;
string childKey5 = string.Empty;

foreach(System.Data.DataRow dr in ThisUD110A.dataView.Table.Rows)
{
//MessageBox.Show(dr[“ChildKey1”].ToString());
if(dr[“ChildKey1”].ToString() == “test”)
{
dr.BeginEdit();
dr[“Checkbox01”] = true;
dr.EndEdit();
}

}

}

I get an object reference not set to an instance of an object and I am guessing maybe it is because my DataView isn’t called UD110A

Hmmm. This is much harder because I don’t have your form.

Its a BAQDataView not an Epi Data View

Ah okay, that helps. I am not sure that you can update that then…

You definitely need to call your adapter then. What I don’t understand Shannon is that in your original code you are looping through your grid and then updating the adapter as if the adapter and the grid are the same thing. In other words, you are getting your row number from the grid and then updating the adapter using that row number. What makes you think that they match row for row?

Which is why I was trying to update the Business Object and I wasn’t just updating the grid.

1 Like

The other thing that may happen (if we get there) is that even when you update using the adapter, the grid on the screen may or may not change to the updated value… we may have to look on the forum for a way to get the grid to refresh after your update.

Yes, I have a method to refresh the BAQDataView already. It is just getting the correct child key row to update is the problem.

What version are you on?

Epicor 10

Shannon Kearney

Shannon, I didn’t know how to get rows in my adapter… I have never done this before.

I had to call my adapter.GetByID(key1,key2,key3,key4,key5); You’ll see it in my code.

Once I did that then I was able to loop through the child rows and update them when I found a matching child row based on criteria in the if statement.

Can you try this code?

	private void Test()
	{

		UD110Adapter adapter2 = new UD110Adapter(this.oTrans);
		adapter2.BOConnect();
		adapter2.GetByID("test","test","","","");
		foreach(DataRow dr in adapter2.UD110Data.UD110A.Rows)
		{
			if(dr["ChildKey1"].ToString() == "test")
			{
				dr.BeginEdit();
				dr["Character02"] = "you updated it";
				dr["CheckBox01"] = false;
				dr["CheckBox05"] = true;
				dr.EndEdit();
			}
		}
		adapter2.Update();
		adapter2.Dispose();
	}
1 Like

Yay!!! That worked like a charm. Great job!