从vb.net中的Datatable删除行

时间:2009-03-20 12:19:56

标签: vb.net

重复 How do I delete a row from a GridView during the RowDeleting event?

我在vb.net的代码中有一个数据表。我需要从数据表中删除行。 我的数据表的namw是“temptable”。在我的Gridview控件的rowdeleting事件中。我编写了如下代码:

在Gridview的Row_Deleting事件中:

temptable.Rows.Remove(Gridview1.Datakeys(e.RowIndex)。价值)

但是,它显示如下错误:

“无法将System.Int32强制转换为System.Data.Datarow”。任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:2)

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

它能解决你的问题吗?

答案 1 :(得分:-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