Rows.Remove

  • Thread starter Thread starter Nathan
  • Start date Start date
N

Nathan

I want to delete a row from a dataset, and I use:

Dim SelectedRow() as DataRow = DataSet1.Table1.Select("Selection Criteria")
DataSet1.Table1.Rows.Remove(SelectedRow(0))

The SelectedRow returns 1 row = SelectedRow(0). This successfully removes
the row from the dataset, but upon calling the update command
(DataAdapter1.Update(DataSet1, "Table1") the database is not updated. When I
refresh the dataset, the removed row is still there. The update command
works successfully with inserted rows and other changes made to the dataset.
I have also tried using the SelectedRow().Delete and AcceptChanges, and I
get the exact same results. What's going wrong?
 
Hi Nathan,

Use delete or deleteAt, remove and removeAt, remove also the information
that it is deleted.


Cor
 
Just to further clarify what Cor said. When you use the remove or removeAt
methods. There is nothing left for update to use to update/delete the
corresponding row in the database. Delete method however, marks the row for
deletion, and therfore when the Update Method of the adapter runs, it knows
a row has been marked for removal from the database.

Regards - OHM
 
Nathan,
In addition to the others comments.

Calling DataRow.Delete marks the row to be deleted.
Calling DataRow.Remove physically removes the row from the collection.
Calling DataSet, DataTable, DataRow AcceptChanges marks the respective rows
as processed (unmodified).

DataAdapter.Update only processes rows that are not marked as Unmodified.

Hence calling DataRow.Delete followed by AcceptChanges causes nothing to
occur on your database.

David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press
covers this plus a plethora of other items about ADO.NET. I highly recommend
it as a good tutorial for ADO.NET & a good desk reference once you know
ADO.NET.

Hope this helps
Jay
 
Thanks Jay. The delete method works without the accept changes. Obviously I
misunderstood something in the little info I have on this at the moment.
 
Back
Top