Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SqlCommandBuilder class
Message
 
 
To
14/04/2014 14:20:24
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01598513
Message ID:
01598625
Views:
23
>>>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.

I re-tested and it seems to work now. I am wondering if the call to GetUpdateCommand is needed or not, I'll try to remove it and re-test.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform