2013-02-20 254 views
2

我在VB.NET項目如下system.data.oledb.oledbexception:語法錯誤INSERT INTO語句中

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 

我得到一個錯誤,當我嘗試在插入添加值代入聲明對此有何建議? system.data.oledb.oledbexception:語法錯誤INSERT INTO語句在system.data.oledb.command.exceutecommandtexterrorhandling(oledbhresult hr) at systems.data.oledb.oledbcommand.executecommandtext(object & executeresult)..... 。

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

在管線29

由於提前....

回答

3

通過"INSERT INTO MCA (URno,SName,Fname,CAddress)"替換"INSERT INTO MCA (URno,SName,Fname,CAddress,)"。你已經指定了一個多餘的逗號

+0

有時你肯定需要一個外人的視角,現在我的朋友你這樣做了...... – CrashOverride 2013-02-20 04:43:04

+0

@ user1897472同意:) – 2013-02-20 04:44:27

相關問題