2014-03-26 77 views
0

我嘗試了連接我的數據庫(MS訪問)到Visual basic.But它想出了以下錯誤:其他信息:語法錯誤INSERT INTO語句中

A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll 

    Additional information: Syntax error in INSERT INTO statement. 

    If there is a handler for this exception, the program may be safely continued. 

我用下面的代碼。請查看是否有任何error..please幫助我吧.. 的代碼是:

Private Sub frmGive_Load(sender As Object, e As EventArgs) Handles Me.Load 
    con = New OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:\Users\AntivirUS Vandry\Documents\Visual Studio 2013\Projects\Give And Get\dbaseMain.mdb") 
    Dim sql As String = "Select * from tblGive" 
    Dim dbcmd As OleDbCommand = New OleDbCommand(sql, con) 
    con.Open() 
    Dim dbadapter As OleDbDataAdapter = New OleDbDataAdapter(sql, con) 
    Dim db As DataSet = New DataSet("TABLE") 
    dbadapter.Fill(db, "TABLE") 
    'create new instance of table so that row can be accessed 
    Dim dt As New DataTable 
    dt = db.Tables("TABLE") 
    CmbGenre.Text = dt.Rows(0)(0) 
    CmbLanguage.Text = dt.Rows(0)(1) 
    txtNMovie.Text = dt.Rows(0)(2) 
    txtFName.Text = dt.Rows(0)(3) 
    txtLname.Text = dt.Rows(0)(4) 
    CmbClass.Text = dt.Rows(0)(5) 
    txtnull.Text = dt.Rows(0)(6) 
End Sub 

有在them.Including文本框和組合框之間的一些代碼。

Public Sub submit() 
    con = New OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:\Users\AntivirUS Vandry\Documents\Visual Studio 2013\Projects\Give And Get\dbaseMain.mdb") 
    con.Open() 

    Dim sql As String 
    sql = "Insert into tblGive (Genre,Language,NMovie,FName,LName,Class,SaveDate)" + "VALUES (" & CmbGenre.Text & "','" & CmbLanguage.Text & "','" & txtNMovie.Text & "','" & txtFName.Text & "','" & txtLname.Text & "','" & CmbClass.Text & "','" & txtnull.Text & "')" 
    MsgBox(sql) 
    Dim dbcmd As OleDbCommand 
    dbcmd = New OleDbCommand(sql, con) 
    dbcmd.ExecuteNonQuery() 
    MsgBox("Saved") 
End Sub 
+0

確保您不使用任何關鍵字作爲列名在表 –

回答

0

您在values關鍵字的開頭缺少單引號。

換句話說,

VALUES (" & CmbGenre.Text & "','" & CmbLanguage.Text & 

應該

VALUES ('" & CmbGenre.Text & "','" & CmbLanguage.Text & 
相關問題