插入到语句中的语法错误 [英] Syntax error on insert into statement

查看:94
本文介绍了插入到语句中的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试更新表格时出现语法错误。我是Access的新手,似乎无法通过大量研究和书籍阅读找到问题。访问2016和Visual Studio 2015,使用visual basic。



我尝试过:



I am getting a syntax error when I try to update my table. I am new to Access and can't seem to find the problem with a lot of research and book reading. Access 2016 and Visual studio 2015 , using visual basic.

What I have tried:

Access.ExecQuery("INSERT INTO Log (LDate, LTime, HCall, " &
            "State, County, Band, Freq, Mode, MCall, HRST, MRST, " &
           "HOper, MOper, RunStart, RunEnd, NetDuration, HomeCounty, CountyLine) " &
          "VALUES(@LDate,@LTime,@HCall,@State,@County,@Band,@Freq,@Mode,@MCall,@HRST,@MRST,@Hoper,@Moper,@RunStart,@RunEnd,@NetDuration,@HomeCounty,@CountyLine);")



这是我获取参数并将其放入列中的代码。请帮忙。


this is the code I have that takes the parameter and places it into the column. Please help.

推荐答案

试试这个:



Try this:

Private Sub AddLogEntry()
Using DBCon As New OleDbConnection(<PUT ACCESS DB CONNECTION STRING HERE>),
DBCmd As New OleDbCommand("",DBCon)

 DBCmd.CommandText = "INSERT INTO Log (LDate, LTime, HCall, " &
"State, County, Band, Freq, Mode, MCall, HRST, MRST, " &
"HOper, MOper, RunStart, RunEnd, NetDuration, HomeCounty, CountyLine) " &
"VALUES(@LDate,@LTime,@HCall,@State,@County,@Band,@Freq,@Mode,@MCall,@HRST,@MRST,@Hoper,@Moper,@RunStart,@RunEnd,@NetDuration,@HomeCounty,@CountyLine);"

 With DBCmd
 .Parameters.AddWithValue("@LDate", lblDate.Text)
 .Parameters.AddWithValue("@LTime", lblClock.Text)
 .Parameters.AddWithValue("@HCall", txtCall.Text)
 .Parameters.AddWithValue("@State", cbxState.Text)
 .Parameters.AddWithValue("@County", cbxCounty.Text)
 .Parameters.AddWithValue("@Band", cbxBand.Text)
 .Parameters.AddWithValue("@Freq", cbxFreq.Text)
 .Parameters.AddWithValue("@Mode", cbxMode.Text)
 .Parameters.AddWithValue("@Mcall", lblMCall.Text)
 .Parameters.AddWithValue("@HRST", cbxHRst.Text)
 .Parameters.AddWithValue("@MRST", cbxMRst.Text)
 .Parameters.AddWithValue("@Hoper", cbxHOper.Text)
 .Parameters.AddWithValue("@Moper", cbxMOper.Text)
 .Parameters.AddWithValue("@RunStart", txtRStart.Text)
 .Parameters.AddWithValue("@RunEnd", txtREnd.Text)
 .Parameters.AddWithValue("@NetDuration", lblNetDur.Text)
 .Parameters.AddWithValue("@HomeCounty", lblHomeCounty.Text)
 .Parameters.AddWithValue("@CountyLine", cbxCountyL.Text)
 End with

 DBCon.Open()
 if DBCmd.ExecuteNonQuery() = 1 Then
  MsgBox("Row was added SUCCESFULLY.")

  Me.RefreshGrid()
 Else
  MsgBox("Insert FAILED.")
 Endif
 DBCon.Close()
End Using

End Sub


这篇关于插入到语句中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆