Update via dataadapter without fill first

  • Thread starter Thread starter Michael Combs
  • Start date Start date
M

Michael Combs

I am attempting to update a table using primary key data without first
filling a datatable. Here are the details...

I am filling a datatable from a SQL Server table and then storing
that information to be transferred and used remotely. The table data
does contain a primary key (standard autoincrement id) which is used
to apply any updates to changed data. At a later time when those data
changes come back to the local server I want to build a datatable with
the updated information (and primary key) and issue those changes to
the database. The problem of course is that building the datatable
from the inbound data causese the datarows to have a rowstate of added
rather than modified. I've attempted to call acceptchanges on those
rows and then subsequently setting the ID field so that the rowstate
becomes modified. However, upon calling update, I get a status of
SkipCurrentRow in the RowUpdating event of the dataadapter. I've tried
setting the status to Continue in that event. This causes a subsequent
exception to be thrown which is "Update requires the command clone to
be valid.". Any suggestions?

Thanks in advance,

Michael Combs
 
Actually, no that doesn't help. I understand the basics of data adapters,
etc.



My problem is that I want to create a row from scratch in a datatable and
give it a primary key value that I know is already in the database (from a
lookup that occurred previously). Then I want that row to update the row in
the database with the corresponding primary key. The data adapter wants to
insert that row because the rowstate is 'Added'. I have attempted to call
'AcceptChanges' and then make a modification to the row so that its rowstate
becomes 'Modified'. However, in the RowUpdating even the status is
'SkipCurrentRow'. How do I get a dataadapter to perform an update instead of
an insert when I build the row from scratch rather that by using the Fill
method.



Thanks.
 
Why not simply construct a Command object that has an UPDATE statement as
the CommandText and use ExecuteNonQuery?

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top