解析查询时出错。 [令牌行号= 1,令牌行偏移= 36,令牌错误=名称]

时间:2016-12-13 09:23:59

标签: visual-studio vb.net-2010

我想从不同的文本框,标签和组合框中获取用户输入,然后使用SQL CE 3.5将其插入到数据网格中,我尝试将它们作为字符串放入变量中,但我仍然遇到问题这段代码:

Private Sub addToDb_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addToDb_btn.Click
    Dim IDVal As String = accIdVal_Lbl.Text
    Dim Pwrd As String = accPassVal_Lbl.Text
    Dim AcTp As String = accTyp_Cbx.Text
    Dim FNm As String = accFrstNm_Txbx.Text
    Dim MNm As String = accMidNm_Txbx.Text
    Dim LNm As String = accLstNm_Txbx.Text
    Dim UsrNm As String = accUsrNm_Txbx.Text
    cmd = New SqlCeCommand("INSERT INTO userAccounts(ID, First Name, Middle Name, Last Name, Username, Password, Account Type) VALUES('" & IDVal & "',  '" & FNm & "',  '" & MNm & "',  '" & LNm & "',  '" & UsrNm & "',  '" & Pwrd & "', '" & AcTp & "')", con)
    If con.State = ConnectionState.Closed Then con.Open()
    cmd.ExecuteNonQuery()

    con.Close()
End Sub

1 个答案:

答案 0 :(得分:0)

在[]:

中加上标识符
INSERT INTO [userAccounts]([ID], [First Name], [Middle Name], [Last Name], [Username], [Password], [Account Type]