>>>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 know if there is a way to check the update command without implementing the OnRowUpdating or SQL Server Profiler. When I check it on the Update command the UpdateCommand is null and it's null after. I want to make sure it is actually what it is supposed to be. I did check it before, but want to be able to trace it.
If it's not broken, fix it until it is.
My Blog