2

私は次のようにVB.NETにプロジェクトを持っています

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

Insert intoステートメントで値を追加しようとすると、エラーが発生します。これに関する提案はありますか?system.data.oledb.oledbexception:systems.data.oledb.oledbcommand.executecommandtext(object&executeresult)..。のsystem.data.oledb.command.exceutecommandtexterrorhandling(oledbhresult hr)のINSERTINTOステートメントの構文エラー。

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

29行目。

前もって感謝します....

4

1 に答える 1

3

"INSERT INTO MCA (URno,SName,Fname,CAddress,)"に置き換え"INSERT INTO MCA (URno,SName,Fname,CAddress)"ます。冗長なコンマを指定しました

于 2013-02-20T04:36:34.433 に答える