By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,742 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,742 IT Pros & Developers. It's quick & easy.

Problem deleting rows from dataset (VS2003, VB)

P: n/a
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?

Mar 27 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"marshallarts" <st****@westnet.net.au> schreef in bericht
news:11**********************@j33g2000cwa.googlegr oups.com...
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?

Mar 27 '06 #2

P: n/a
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.

Mar 27 '06 #3

P: n/a

"Steve Marshall" <st****@westnet.net.au> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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?

Mar 27 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.