>>>>>Try not setting the adapter.UpdateCommand. See remarks section under
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand%28v=vs.110%29.aspx and the fifth paragraph at
http://msdn.microsoft.com/en-us/library/tf579hcz%28v=vs.110%29.aspx for reasons why it shouldn't be set.
>>>>
>>>>If I am not setting it myself, it remains NULL. Do you see what is missing in my code? I populate the adapter by passing SqlCommand.
>>>>
>>>>I moved creating of the builder into the UpdateRows() method, but it was originally in the Populate method and still all the adapter's commands were null.
>>>>
>>>>Adapter is defined as private property of the class.
>>>
>>>You are setting it in this line:
adapter.UpdateCommand = builder.GetUpdateCommand(true);
>>>That sets it to a single command that doesn't change. It needs to be left to null so that the command builder hooks into the OnRowUpdating event (see second paragraph under remarks at
http://msdn.microsoft.com/en-us/library/System.Data.SqlClient.SqlCommandBuilder%28v=vs.110%29.aspx) and populates it at that time for the row being updated. Based on the example there, you may need to call builder.GetUpdateCommand, but don't assign it to adapter.UpdateCommand.
>>
>>Do you think I don't really need the OnRowUpdating method handler? I only added it to check the command.
>
>You shouldn't need it. I just had you add it for debugging.
I was debugging it again and this time somehow it didn't hit that method even though I haven't removed it. I also see the command being null again. Wondering if it reverts to null after the updating.
I only commented out the GetUpdateCommand. I'll un-comment and re-test one more time before removing the hook.
If it's not broken, fix it until it is.
My Blog