Home All Groups Group Topic Archive Search About

Problem deleting rows from dataset (VS2003, VB)

Author
27 Mar 2006 9:41 AM
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?

Author
27 Mar 2006 10:37 AM
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

Show quoteHide quote
"marshallarts" <ste***@westnet.net.au> schreef in bericht
news:1143452490.735223.279110@j33g2000cwa.googlegroups.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?
>