我需要你的帮助请! 我有一张桌子:tblCustomer。 (串行,名称,电子邮件,地址)
我做了以下事情: insert-update-delete in dataset(包含表tblCustomer)
我需要做的是,我需要你的帮助,是: dataview中的insert-update-delete。 我试着做以下事情:
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 serial is null, that means the row is new and deleted
' so no need to add it to database
If Not IsDBNull(dv!serial) Then
' delete row from database
Dim _SQL As String = "DELETE FROM tblCustomer WHERE Serial = " & dv!serial.ToString
' open the connection and execute the delete command
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= '" & txtSerial.Text & "'"
End If
Next
我收到此错误:Conversion from string "serial" to type 'Integer' is not valid.
在这一行:If Not IsDBNull(dv!serial) Then
同样的错误:Dim _SQL As String = "DELETE FROM tblCustomer WHERE Serial = " & dv!serial.ToString
答案 0 :(得分:0)
serial
是什么类型的? Integer
我猜错了。此外,您似乎正在传递文字字符串值“serial”而不是数字。
另外,在您的两个DELETE
语句中,您将 WITH 和 WITHOUT ' '
传递给它。
删除' '
。
那个_SQL字符串变量是什么?你没有使用它。
尝试:
If Not IsDBNull(dv!serial) Then
' open the connection and execute the delete command
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= " & txtSerial.Text
End If