0

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?

2
  • @Vineetha: Are you also ramyatk06? Why so many exact duplicates of their (ramyatk06) questions? Commented Mar 20, 2009 at 12:27
  • No,i am not ramyatk06.we are colleagues Commented Mar 21, 2009 at 6:13

2 Answers 2

2

temptable.Rows[e.RowIndex].Delete()

Does it solve your problem?

Sign up to request clarification or add additional context in comments.

1 Comment

well, with parentheses since he's in VB
-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

1 Comment

This is nothing to do with a DataTable as the OP asked. And in any case you are promoting SQL injection vulnerabilities with this code not to mention using a recordset which is outdated.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.