2013-07-08 41 views
0

我正在使用下面的代碼將數據保存到MS-Access 2007表中。但它拋出一個表達式如下:將數據插入到vb 2010中的訪問數據庫時出錯

{"Syntax error (missing operator) in query expression '0','0','0','0','0','0','0','0')'."} 

我附上下面的代碼:

cmd.CommandText = "INSERT INTO Daily_EB_Consumption (EB_S1, EB_S2, EB_S3, EB_S4, EB_S5, EB_Indus, EB_LH, EB_Total, EB_Date) " & _ 
    " VALUES(" & Me.txt_S1.Text & "','" & _ 
     Me.txt_S2.Text & "','" & Me.txt_S3.Text & "','" & Me.txt_S4.Text & "','" & _ 
     Me.txt_S5.Text & "','" & Me.txt_Indus.Text & "','" & Me.txt_LH.Text & "','" & _ 
     Me.txt_Total.Text & "','" & Me.dt_EB.Value & "')"  

請人用這個錯誤

回答

1

您已經使用了撇號,但僅在右側幫助。你必須用撇號包裝這些值:

VALUES('" & Me.txt_S1.Text & "', ... 

但是你打開SQL注入,所以你應該使用參數。

using parameters inserting data into access database

+0

感謝您的幫助添先生...現在代碼正確 – user2559865

+0

工作@ user2559865:考慮接受的答案即可。別客氣。 –

相關問題