2017-10-09 1145 views
0
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.所有的表名和列名都是正確的,但總是出現錯誤。INSERT TO STATEMENT中的語法錯誤

+0

您應該知道,使用DAtaTable和DataAdapter時,不需要任何代碼。數據庫提供者對象可以完成所有工作。 – Plutonix

回答

0

嘗試用支架和適當的間距和問號:

Data = "insert into ProductReceiptDetails (receiptID,[Product ID],ProductCount,BuyPrice,SellPrice) values (?,?,?,?,?)" 

,並使用Command3.Parameters.Add("@parameter0", ..)指定的數據類型。

+0

確實。冒號前綴是針對我認爲的Oracle,或者可能是MySQL。其中的一個,但絕對不是Access。 – jmcilhinney