>Ok, but how do I 'attach' the data table to the DataAdapter? I'm not sure
>of the syntax.There is no "attaching", I have no clue what you mean by that.
You have two options.
1) You can make your original oDataAdapter that you created with your oDataFactory scoped to your whole form (or maybe you're using a separate DataAccess class?), then you can re-use it in your UpdateData() method. If you do this, you might as well also create a DBCommandBuilder here as well ... this will automatically generate your insert,etc. commands for you (assuming that your data has a PK).
DbDataAdapter oDataAdapter = oDataFactory.CreateDataAdapter();
oDataAdapter.SelectCommand = oCommand;
DBCommandBuilder oCommandBuilder = oDataFactory.CreateCommandBuilder();
oCommandBuilder.DataAdapter = oDataAdapter;
-or-
2) Create another DataAdapter and CommandBuilder in your UpdateData() method and use them there. I would do it this way, since my UI is totally disconnected from the DataAcess, which is in a separate class).
public bool UpdateData(DataTable oDataTable)
{
bool bRetVal = true;
DataTable oChanges = oDataTable.GetChanges(DataRowState.Modified);
if (oChanges.Rows.Count > 0)
{
oDataAdapter.Update(oDataTable);
}
return bRetVal;
}
I don't typically use the CommandBuilder, but as a tool to get you started it's good for newbies.
~~Bonnie
>
>
>
>>In your UpdateData() method, you could instantiate another DataAdapter, set up the properties for your UpdateCommand (you could use the SqlCommandBuilder to help you), then use that to do your dataadapter.Update().
>>
>>~~Bonnie
>>
>>
>>
>>>The question is, what do I do with this DataTable?
>>>
>>>My query code returns a DataTable, which I can then pass into the UpdateData
>>>procedure.
>>>
>>>Can I somehow 'attach' the data table to the DataAdapter?
>>>
>>>
>>>
>>>
>>>
>>>>The dataadapter has properties for Select, Insert, Update, delete;
>>>>
>>>>just create you update command:
>>>>
>>>>
>>>>dataadapter.UpdateCommand = new sqlCommand("UPDATE table.....blah...blah...blah", connection);
>>>>
>>>>
>>>>then simply call
>>>>
>>>>dataadapter.Update(your dataset);
>>>>