-
Delete row
Hello
i have the dataset (data) which contains numbers of rows and
these rows are displayed in datagrid
i added delete command coloum in the datagrid
and i want when the user click the delete button
the associated row is deleted from the dataset and from the database
the code is:
Dim id As Integer
id = e.Item.ItemIndex
Dim strdel As String = "delete from AllAlumni where AllAlumniNum=" & id
Dim sqlcommand As SqlCommand = New SqlCommand(strdel, cnn)
Dim adapt As New SqlDataAdapter
adapt.UpdateCommand = sqlcommand
adapt.Update(data, "AllAllumni")
it doesn't work
thanks
sara
-
Re: Delete row
Is "data" your dataset?
data.Tables(0).Rows(e.Item.ItemIndex).Delete()
You can then perform your dataadapter's UPDATE().
-
Re: Delete row
Dear mendhak
Yes, Data is the dataset
I did this command
data.Tables(0).Rows(e.Item.ItemIndex).Delete()
but the row is deleted from the dataset only , the database is never changed
-
Re: Delete row
-
Re: Delete row
Ya
using the following command
adapt.UpdateCommand = sqlcommand
adapt.Update(data, "AllAllumni")
-
Re: Delete row
adapt.DeleteCommand = sqlcommand
-
Re: Delete row
normally when i need to delete a record using a datagrid, i store the pk id in a hidden column. then on the itemcommand i search the dataset for it, delete the row, update, and then rebind. this will guarantee that you have the right record.
row = ds.tables(0).rows.find(e.item.cells(0).text)
row.delete
da.update(ds)
ds.acceptchanges
dgr.datasource = ds
dgr.databind