Dim ProductID As String = DataGridView2.Rows(Newewew).Cells(0).Value
Dim BuyPrice As Decimal = DataGridView2.Rows(Newewew).Cells(2).Value
Dim SellPrice As Decimal = DataGridView2.Rows(Newewew).Cells(3).Value
Dim ProductCount As Decimal = DataGridView2.Rows(Newewew).Cells(4).Value
Dim Command3 As New OleDb.OleDbCommand
Data = "insert into ProductReceiptDetails" &"(receiptID,Product ID,ProductCount,BuyPrice,SellPrice) " & "values " & "(:0,:1,:2,:3,:4)"
Command3.Connection = Newconnection
Command3.Transaction = NewTransac
Command3.CommandText = Data
Command3.Parameters.AddWithValue(":0", receiptID)
Command3.Parameters.AddWithValue(":1", ProductID)
Command3.Parameters.AddWithValue(":2", ProductCount)
Command3.Parameters.AddWithValue(":3", BuyPrice)
Command3.Parameters.AddWithValue(":4", SellPrice)
Command3.ExecuteNonQuery()
Command3.Dispose()
' ...
Dim Data As String = "INSERT INTO ReceiptDetails (ReceiptDate,ReceiptTotal) " & "values " & "(:0,:1)"
Dim Command As New OleDb.OleDbCommand
Command.Connection = Newconnection
Command.Transaction = NewTransac
Command.CommandText = Data
Command.Parameters.AddWithValue(":0", Now.Date)
Command.Parameters.AddWithValue(":1", TextBox4.Text)
Command.ExecuteNonQuery()
你能帮我解决这个错误吗?我使用的是VS 2008和MS Access 2013.所有的表名和列名都是正确的,但总是会出错。
答案 0 :(得分:0)
尝试使用括号和正确的间距和问号:
Data = "insert into ProductReceiptDetails (receiptID,[Product ID],ProductCount,BuyPrice,SellPrice) values (?,?,?,?,?)"
并使用Command3.Parameters.Add("@parameter0", ..)
指定数据类型。