我有这段代码:
Dim dv As New DataView(_DataSet.Tables(0))
' select deleted rows
dv.RowStateFilter = DataViewRowState.Deleted
For _irow As Long = 0 To dv.Table.Rows.Count - 1
If Not IsDBNull(dv!serial) Then
txtSerial.Text = (dv!serial).ToString
Dim strconnection As String = "Data Source=EASMAR-PC;Initial Catalog=Database Connection;Integrated Security=True;"
Dim _cn As SqlConnection = New SqlConnection(strconnection)
_cn.Open()
Dim cmd As New SqlCommand
cmd.CommandText = "Delete from tblCustomer where serial= " & (dv!serial).ToString
End If
Next
我只是循环访问数据视图(如果删除了rowwstate,则从数据库中删除)。
我收到此错误:Conversion from string "serial" to type 'Integer' is not valid.
在这一行:If Not IsDBNull(dv!serial) Then
有什么想法吗?
答案 0 :(得分:0)
您需要访问DataView的ROW(整数)和COLUMN。您收到错误,因为您使用String(Serial)作为第一个参数,该参数应该是Row索引整数。像第一行的0一样。
dtvRow(0)("Serial")
在你的情况下
dv(_irow)(serial)
可能会有所帮助:)