system.data.oledb.oledbexception:INSERT INTO语句中的语法错误

时间:2022-06-03 22:22:58

I have a Project in VB.NET as follows

我在VB.NET中有一个Project如下

Public Class MCARegis
    Dim con As New OleDb.OleDbConnection()

    Private Sub MCARegis_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        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()
        MsgBox("opened")
    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click

        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 MCA (URno,SName,Fname,CAddress,)" + "VALUES (" & CInt(txtUrn.Text) & ",'" & txtName.Text & "','" & txtFname.Text & "','" & txtCAdd.Text & "');"
            Dim sqlcommand As New OleDb.OleDbCommand(sqlquery)

            With sqlcommand
                .CommandText = sqlquery
                .Connection = con
                .ExecuteNonQuery()
            End With
            MsgBox("Record Added")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

End Class

I am getting an error when i try to add values at the Insert into statement any suggestions on this? system.data.oledb.oledbexception:Syntax error in INSERT INTO Statement at system.data.oledb.command.exceutecommandtexterrorhandling(oledbhresult hr) at systems.data.oledb.oledbcommand.executecommandtext(object&executeresult)......

当我尝试在Insert into语句中添加值时,我收到一个错误吗? system.data.oledb.oledbexception:在system.data.oledb.mandd命令处于system.data.oledb.command.exceutecommandtexterrorhandling(oledbhresult hr)的INSERT INTO语句中的语法错误,发生在systems.data.oledb.oledbcommand.executecommandtext(object&executeresult)......

at system.data.oledb.oledbcomamand.executenonquery()

at line 29.

在第29行。

Thanks in Advance....

提前致谢....

1 个解决方案

#1


3  

Replace "INSERT INTO MCA (URno,SName,Fname,CAddress,)" by "INSERT INTO MCA (URno,SName,Fname,CAddress)". You have specified a redundant comma

将“INSERT INTO MCA(URno,SName,Fname,CAddress,)”替换为“INSERT INTO MCA(URno,SName,Fname,CAddress)”。您已指定冗余逗号

#1


3  

Replace "INSERT INTO MCA (URno,SName,Fname,CAddress,)" by "INSERT INTO MCA (URno,SName,Fname,CAddress)". You have specified a redundant comma

将“INSERT INTO MCA(URno,SName,Fname,CAddress,)”替换为“INSERT INTO MCA(URno,SName,Fname,CAddress)”。您已指定冗余逗号