Reputation: 393
DUPLICATE of How do I delete a row from a GridView during the RowDeleting event?
hi,
i have a Datatable in my code in vb.net.I need to delete rows from the datatable. The namw of my Datatable is "temptable".in my rowdeleting event of a Gridview control.i wrote code as follows:
In the Row_Deleting event of Gridview:
temptable.Rows.Remove(Gridview1.Datakeys(e.RowIndex).value)
But,it shows an error as follows:
"Cannot cast System.Int32 to System.Data.Datarow".Anyone can help me?
Upvotes: 0
Views: 19191
Reputation: 1
Dim intans As Integer
Dim ssql As ADODB.Command
intans = MsgBox("ARE YOU SURE YOU ", vbYesNo, "CONFIRM")
If intans = vbYes Then
ssql = "delete * from supplier_table where id=" & cbocid.Text & ""
conn.Execute (ssql)
rs.MoveNext
If rs.EOF Then
rs.MovePrevious
If rs.BOF Then
MsgBox "No record exit in the table", vbExclamation, "No Record"
End If
End If
MsgBox "RECORD SUCCESSFULLY DELETED", vbInformation, "INFO"
cmdfirst_Click
cbocid.Clear
Do Until rs.EOF
cbocid.AddItem rs.Fields(0).Value
rs.MoveNext
Loop
End If
Upvotes: -1