在vb 2010中将数据插入访问数据库时出错

时间:2013-07-08 07:54:54

标签: sql vb.net

我使用以下代码将数据保存到MS-Access 2007表中。但它抛出如下表达式:

{"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 个答案:

答案 0 :(得分:1)

您使用过撇号但仅在右侧。你必须用撇号包装值:

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

但是你对SQL-Injection是开放的,所以你应该使用参数。

using parameters inserting data into access database