0

我在插入语句中遇到语法错误。IF语句工作得很好,只是在尝试保存信息时出现此错误

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If txt12Per.Text >= TextBox12.Text And txtGPer.Text >= TextBox11.Text And TextBox1.Text >= TextBox10.Text Then
            Try
                'Dim da As OleDb.OleDbDataAdapter
                Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
                Me.con = New OleDb.OleDbConnection()
                con.ConnectionString = dbprovider
                con.Open()

                Dim sqlquery As String = "INSERT INTO MCAscheduled (URno,SName,hsc,gper,pgper,pstatus,cname,hrname,position,hscinter,ginter,pginter,comments)" + "VALUES (" & CInt(txtUrn.Text) & ",'" & txtName.Text & "'," & CInt(txt12Per.Text) & "," & CInt(txtGPer.Text) & "," & CInt(TextBox1.Text) & ",'" & ComboBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & ComboBox4.Text & "'," & CInt(TextBox12.Text) & "," & CInt(TextBox11.Text) & "," & CInt(TextBox10.Text) & ",'" & TextBox9.Text & "');"
                Dim sqlcommand As New OleDb.OleDbCommand(sqlquery)

                With sqlcommand
                    .CommandText = sqlquery
                    .Connection = con
                    .ExecuteNonQuery()
                    con.Close()
                    txtUrn.Text = ""
                    txt12Per.Text = ""
                    txtGPer.Text = ""
                    txtName.Text = ""
                    cmbNameofGCourse.Text = ""
                End With
                MsgBox("Record Added")
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        Else
            MsgBox("Student Not eligible for the requested company")
        End If
    End Sub

有人可以帮我解决这个问题吗......

4

4 回答 4

4

您试图插入 13 列,但只提供 11 个值!

于 2013-02-24T13:04:29.690 回答
4

您有 13 个字段可以插入值,但只有 11 个值。

于 2013-02-24T13:02:48.360 回答
2

使用括号,它会正常工作。

Dim sqlquery As String = "INSERT INTO MCAscheduled **([URno],[SName],[hsc],[gper],[pgper],[pstatus],[cname],[hrname],[position],[hscinter],[ginter],[pginter],[comments])"** + "VALUES (" & CInt(txtUrn.Text) & ",'" & txtName.Text & "'," & CInt(txt12Per.Text) & "," & CInt(txtGPer.Text) & "," & CInt(TextBox1.Text) & ",'" & ComboBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & ComboBox4.Text & "'," & CInt(TextBox12.Text) & "," & CInt(TextBox11.Text) & "," & CInt(TextBox10.Text) & ",'" & TextBox9.Text & "');"
于 2013-08-02T02:27:35.203 回答
0

不得不将位置字段更改为其他不知道为什么但它有效

Dim sqlquery As String = "INSERT INTO MCAscheduled (URno,sname,hsc,gper,pgper,pstatus,cname,hrname,hscinter,ginter,pginter,comments,post,course,pcourse)" + "VALUES (" & CInt(txtUrn.Text) & ",'" & txtName.Text & "'," & CInt(txt12Per.Text) & "," & CInt(txtGPer.Text) & "," & CInt(TextBox1.Text) & ",'" & ComboBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "'," & CInt(TextBox12.Text) & "," & CInt(TextBox11.Text) & "," & CInt(TextBox10.Text) & ",'" & TextBox9.Text & "','" & ComboBox1.Text & "','" & cmbNameofGCourse.Text & "','" & TextBox5.Text & "');"
于 2013-02-24T18:17:23.627 回答