Problem deleting rows from dataset (VS2003, VB)

M

marshallarts

Hello,

I have a datagrid (grdShots) on a form, and a button to allow the user
to delete records from the dataset underlying the grid. My code
appears to work, because the row disappears from the datagrid. But the
delete is not being updated back to the data source, because if I exit
the app then start it again, the record reappears in the grid - it has
not been deleted. Code for deleting the row is as follows. Column 0
in the grid is the ID of the record, which is its primary key.

Dim iImage as Long
Dim dr as DataRow

iImage = grdShots.Item(grdShots.CurrentRowIndex, 0)
If MsgBox("Are you sure you want to delete this?",
MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
dr = dsShots.Tables("Shot").Rows.Find(iImage)
dsShots.Tables("Shot").Rows.Remove(dr)
daShots.Update(dsShots)
End If

What more do I need to do?
 
C

Cor Ligthert [MVP]

Marshall,

Replace the remove by a "delete" equivalent.

The remove, removes a datarow from a datatable/dataset
The delete marks a row as to be removed by the next update or by an
acceptchanges.

I hope this helps,

Cor
 
S

Steve Marshall

Unbelievable! Thank you, that worked. When would anyone use the
Remove method, for heaven's sake?? I can't get my head around what its
purpose is.
 
H

Homer J Simpson

Unbelievable! Thank you, that worked. When would anyone use the
Remove method, for heaven's sake?? I can't get my head around what its
purpose is.

Possibly after a Remove that row will not be altered on the DB after a
resynch?
 

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

Top