Delete selected value from gridview and database
hi, i am using gridview and how can i delete my selected row of value from the database?
i got 4 column of data from database which is code behind
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Nilanka DharmadasaPosted Nov 5, 2009, 3:39 AM
You haven't changed '2' as I asked. It should be 0 as name is the first column in your gird.
change your code as follows.
Dim row As GridViewRow = GridView1.SelectedRow
cmd.CommandText = "DELETE FROM user_profile WHERE name='" & row.Cells(0).Text & "'"
If you still getting the error do a null check for row and row.Cells(0).
Soh Kok TingPosted Nov 5, 2009, 3:49 AM
Soh Kok TingPosted Nov 5, 2009, 2:12 AM
Nilanka DharmadasaPosted Nov 5, 2009, 2:04 AM
Dim row As GridViewRow = GridView1.SelectedRow
cmd.CommandText = "DELETE FROM user_profile WHERE name='" & row.Cells(2).Text & "'"
Here, 2 shuld be changed to the index of your column 'name' in the gridview. (starting from 0)
Soh Kok TingPosted Nov 5, 2009, 1:44 AM
Soh Kok TingPosted Nov 5, 2009, 1:42 AM
Nilanka DharmadasaPosted Nov 5, 2009, 1:36 AM
Soh Kok TingPosted Nov 5, 2009, 1:15 AM