How to delete from a DataSet

  • Thread starter Thread starter Rik Hemsley
  • Start date Start date
R

Rik Hemsley

Hi,

I'm trying to delete a row from a recordset, but the database doesn't
seem to be changed at all.

Does this code look incorrect? AFAICT from reading MSDN, it's the Right
Way to delete a row...

MyDataAdapter.Fill(MyDataSet)
Dim r As MyDataSet.MyRow = MyDataSet.MyTable.Rows(0)
MyDataSet.MyTable.RemoveMyTableRow(r)
MyDataAdapter.Update(MyDataSet)

Cheers,
Rik
 
Note to self: Re-read the documentation more than twice before posting
to newsgroup.

Rik said:
MyDataAdapter.Fill(MyDataSet)
Dim r As MyDataSet.MyRow = MyDataSet.MyTable.Rows(0)
MyDataSet.MyTable.RemoveMyTableRow(r)

The above two line should probably be replaced with:

MyDataSet.MyTable.Rows(0).Delete
MyDataAdapter.Update(MyDataSet)

This seems to work now.

Cheers,
Rik
 
There are two similar operations on Rows which are easily confused. Calling
Delete() on the required row will mark the row as deleted and will cause it
to be removed from the database when the DataAdapter.Update is run on the
DataSet.

Removing the row from the Rows collection of the DataTable will not remove
the record from the database. This is because the row is immediately taken
out of the DataSet and so when Update runs it is not there to trigger a
Delete statement to be sent to the database.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Peter said:
There are two similar operations on Rows which are easily confused. Calling
Delete() on the required row will mark the row as deleted and will cause it
to be removed from the database when the DataAdapter.Update is run on the
DataSet.

Removing the row from the Rows collection of the DataTable will not remove
the record from the database. This is because the row is immediately taken
out of the DataSet and so when Update runs it is not there to trigger a
Delete statement to be sent to the database.

Thanks, that makes perfect sense.

Rik
 
Back
Top