|
-
Jun 29th, 2005, 02:24 AM
#1
Thread Starter
Junior Member
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
-
Jun 29th, 2005, 03:50 AM
#2
Re: Delete row
Is "data" your dataset?
data.Tables(0).Rows(e.Item.ItemIndex).Delete()
You can then perform your dataadapter's UPDATE().
-
Jul 1st, 2005, 03:40 AM
#3
Thread Starter
Junior Member
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
-
Jul 1st, 2005, 04:07 AM
#4
-
Jul 1st, 2005, 04:16 AM
#5
Thread Starter
Junior Member
Re: Delete row
Ya
using the following command
adapt.UpdateCommand = sqlcommand
adapt.Update(data, "AllAllumni")
-
Jul 1st, 2005, 04:25 AM
#6
Re: Delete row
adapt.DeleteCommand = sqlcommand
-
Jul 11th, 2005, 11:20 PM
#7
Junior Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|