INSERT INTO语句中的语法错误添加数据

时间:2022-10-29 15:44:04

I'm having problems with my add data codes, everytime I click the button for adding it says Syntax Error in INSERT INTO statement. I've checked for the spelling of fields, designated textboxes for the fields, table name. What could be the problem these codes?

我在添加数据代码时遇到问题,每次单击按钮添加它都会在INSERT INTO语句中显示语法错误。我已经检查了字段的拼写,字段的指定文本框,表名。这些代码有什么问题?

 If RadioButton1.Checked = True Then
        TextBox16.Text = DataGridView1.RowCount
        Try
            con.Open()
            Dim SqlQuery As String = "insert into tblsched(id,time,day,room,professor,subject,students)VALUES ('" & TextBox16.Text.Trim & "','" & TextBox12.Text.Trim & "','" & TextBox13.Text.Trim & "','" & TextBox1.Text.Trim & "','" & TextBox2.Text.Trim & "','" & TextBox3.Text.Trim & "','" & TextBox10.Text.Trim & "');"
            Dim SqlCommand As New OleDbCommand
            With SqlCommand
                .CommandText = SqlQuery
                .Connection = con
                .ExecuteNonQuery()
            End With
            MsgBox("Schedule Added", MsgBoxStyle.Information, "Added")
            con.Close()
            datagridshow()
        Catch ex As Exception
            MsgBox(ex.Message)
            con.Close()
        End Try

1 个解决方案

#1


0  

As @danielml01 mentioned, it appears you are missing a space between ) and VALUES. It appears that the semi-colon at the end of the statement is the standard syntax I am seeing, although I know that inserts without the semi-colon work for me.

正如@ danielml01所提到的那样,你似乎缺少了一个空间和VALUES之间的空格。看起来语句末尾的分号是我看到的标准语法,虽然我知道没有分号的插入对我有用。

Try:

尝试:

Dim SqlQuery As String = "insert into tblsched(id,time,day,room,professor,subject,students) VALUES ('" & TextBox16.Text.Trim & "','" & TextBox12.Text.Trim & "','" & TextBox13.Text.Trim & "','" & TextBox1.Text.Trim & "','" & TextBox2.Text.Trim & "','" & TextBox3.Text.Trim & "','" & TextBox10.Text.Trim & "');"

#1


0  

As @danielml01 mentioned, it appears you are missing a space between ) and VALUES. It appears that the semi-colon at the end of the statement is the standard syntax I am seeing, although I know that inserts without the semi-colon work for me.

正如@ danielml01所提到的那样,你似乎缺少了一个空间和VALUES之间的空格。看起来语句末尾的分号是我看到的标准语法,虽然我知道没有分号的插入对我有用。

Try:

尝试:

Dim SqlQuery As String = "insert into tblsched(id,time,day,room,professor,subject,students) VALUES ('" & TextBox16.Text.Trim & "','" & TextBox12.Text.Trim & "','" & TextBox13.Text.Trim & "','" & TextBox1.Text.Trim & "','" & TextBox2.Text.Trim & "','" & TextBox3.Text.Trim & "','" & TextBox10.Text.Trim & "');"