none
Deleting records from a dataset with a bound datagrid RRS feed

  • Question

  • I am using VB.NET 2003 and have programmatically (ie by writing lines of code rather than dragging a control onto the form)bound a datagrid to a dataset loaded from a SQL database. I can quite easily delete one selected row from the dataset and the datagrid displays one less record. However, the dataset contains the same number of records - the deleted record still being there but with status 'Deleted'. This presents a problem as I am using the rownumber of the current cell in the datagrid as a basis for selecting the dataset record to perform actions on. Please see my coding below:

     

    cmdBundle = New SqlCommand("Select * from Bundle", cnR)

    daBundle = New SqlDataAdapter

    daBundle.SelectCommand = cmdBundle

    daBundle.Fill(dsBundle, "Bundle")

    dtBundle = dsBundle.Tables("Bundle")

    DataGrid1.SetDataBinding(dsBundle, "Bundle")

    ...

    selectedRow = DataGrid1.CurrentCell.RowNumber

    selectedBundle = DataGrid1.Item(selectedRow, 0)

    drBundle = dtBundle.Select("BundleID = " & selectedBundle)

    ...

    dtBundle.Rows(selectedRow).Delete()

     

    The 1st field of table Bundle is BundleID which is the primary key & an autonumber field

    Is there an obvious solution that I have missed?

     

    Ta, Geoff

    Friday, August 24, 2007 12:50 PM

Answers

All replies