INSERT INTO语句中的语法错误。

时间:2018-05-16 07:45:29

标签: vb.net oledb

Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button1.Click         cs =" Provider = Microsoft.ACE.OLEDB.12.0; Data Source = | DataDirectory | \ coder.accdb"         con =新的OleDbConnection(cs)         con.Open()         cmd =新的OleDbCommand("插入学生信息('" + txtid.Text +"''" + txtroll.Text +& #34;','" + txtfname.Text +"','" + txtlname.Text +"&#39 ;,'" + txtpclass.Text +"','" + txtpname.Text +"',' " + txtmname.Text +"','" + txtfoccupation.Text +"','" + txtmoccupation .Text +"','" + txtaddress.Text +"','" + txtcontact.Text +&#34 ;','" + txtlandl.Text +"','" + txtpschool.Text +"') ",con)

   Dim i As Integer = cmd.ExecuteNonQuery

    If (i >= 0) Then
        MessageBox.Show("Data saved Successfully", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information)

    Else
        MessageBox.Show("Data not  saved Successfully", "Unsuccessfull!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)


    End If
    con.Close()

End Sub

1 个答案:

答案 0 :(得分:0)

insert语句缺少VALUES关键字。请参阅:https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2007/bb208861(v=office.12)

insert into myTable values (val1, val2, val3, ...)

或者:

insert into myTable (col1, col2, col3, ...) values (col1, col2, col3, ...)