PC Review


Reply
Thread Tools Rate Thread

DataAdapter.Update() returns error.

 
 
Manohar
Guest
Posts: n/a
 
      25th Jul 2007
Hi,

I am populating a dataset from a stored procedure, which returns
multiple resultsets. One of the resultset is formed with a join
condition from two tables. I am updating the fields of the
respective
datatable. Then update the first table in the database using
DataAdapter.Update(). This succeeds. Subsequently, I update the
fields of the second table in the datatable and update the
respective(second) table in the database using DataAdapter.Update().
This throws the error, "Concurrency violation: the UpdateCommand
affected 0 of the expected 1 records.". Dataset.HasChanges() returns
true before each update. I give below the code.


// First Table


DataRow dr = dtOrderInfo.Rows[iSelectedRow];
dr.BeginEdit();
// Data Row changes.
....
....
dr.EndEdit();


// connect to database and execute as follows.


cnDatabaseOpen(strdbconnect);
SqlDataAdapter da = new SqlDataAdapter("Select top 0 * from
OrderDetail", cnDatabase);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
da.Update(dtOrderInfo);
da.Dispose();
cnDatabaseClose();


// Second Table


dr = null;
dr = dtOrderInfo.Rows[iSelectedRow];
dr.BeginEdit();
// Data Row changes.
....
....
dr.EndEdit();


// connect to database and execute as follows.


cnDatabaseOpen(strdbconnect);
SqlDataAdapter da = new SqlDataAdapter("Select top 0 * from Orders",
cnDatabase);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
// Following line throws error.
da.Update(dtOrderInfo);
da.Dispose();
cnDatabaseClose();


I get the error in da.Update() for the second table.
Any help would be greatly appreciated.


Thanks
Manohar

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataAdapter.Update() returns error. Manohar Microsoft C# .NET 2 25th Jul 2007 08:47 PM
Error Trapping dataAdapter.update =?Utf-8?B?RExT?= Microsoft ADO .NET 1 29th Jun 2005 09:36 AM
Error on DataAdapter Update Nathan Microsoft ADO .NET 3 8th Aug 2004 11:15 PM
error when update dataadapter Nguyen Microsoft ADO .NET 0 16th Mar 2004 02:54 PM
DataAdapter.Update returns 1 when the row has been deleted Greg Microsoft ADO .NET 1 9th Mar 2004 02:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:30 AM.