Updating a Detached DataRow


Bob Day

Using VS 2003, VB.net, MSDE...

I am trying to 1) create and fill a detached datarow, 2) modify some of its
columns and 3) Update those modifications back to the datasource table. It
is step 3 that is failing, no errors, just 0 rows updated. I think the
problem lies in the fact that the datarow has a row state of "detached" (but
I am not sure how change that, since AddNewRow will create a new row, not
modify an existing one).
Step 1
Dim myDataRow as DataRow = Nothing
myDataRow = myDataAdapeter.Fill()
' myDataRow fills as expected
' I realize in Step 1 I could fill a dataset, set the DataRow = a row in
the dataset, thus making the RowState "Modified" , which then Updates
correctly in Step 3 (this may be the only way to do it).

Step 2
myDataRow.Column = New_Value
' myDataRow has New_Value as expected

Step 3
dim myDataRowArray() as DataRow = {myDataRow}
' myDataRowArray shows a length of 1, and the New_Value is in that 1 item as

Rows_Updated = myDataAdapter.Update(myDataRowArray)
' Rows_Updated = 0, no error, not sure why.

So, why am I not getting anyting updated? I think the

Bob Da

Bob Day

Table.Rows.Add(row) will add it as a seperate additional row, not update the
changes to the existing row in the DataSource. If you have a constraint
(such as a foreign key) that must be unique, then of course, adding this row
will also throw an execption.

Any other thoughts?

Bob Day

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question