tags:

views:

1364

answers:

2

DUPLICATE of http://stackoverflow.com/questions/665751/deletion-from-datatable

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?

+1  A: 

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

Does it solve your problem?

Gustavo
well, with parentheses since he's in VB
Rich
Of course :) Tks for the correction.
Gustavo
Thanks.it worked.your answer is very useful and apt.
Nandini
A: 
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
Harshad