2013-04-14 145 views
-1

我的圖書館系統出現問題。我收到一個錯誤,指出「錯誤數據庫:INSERT INTO語句中的語法錯誤」。我使用Access作爲數據庫。 這裏是我的代碼:錯誤數據庫:INSERT INTO語句中的語法錯誤

Public Class Form7 
    Private Sub Form7_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed 
     Me.Text = "Registration" 
     sqlCon.Close() 
     sqlCon.Close() 
     clear() 
    End Sub 

    Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     If Split(Me.Text, " - ")(1) = "Edit" Then 
      sqlSTR = "Select * From BookRegister WHERE id = " & globalID 
      ExecuteSQLQuery(sqlSTR) 
      If sqlDr.Read Then 
       TextBox1.Text = sqlDr(1) 
       TextBox2.Text = sqlDr(2) 
       TextBox3.Text = sqlDr(3) 
       TextBox4.Text = sqlDr(4) 
       TextBox5.Text = sqlDr(5) 
       TextBox6.Text = sqlDr(6) 
       TextBox7.Text = sqlDr(7) 
       TextBox7.Text = sqlDr(8) 

      End If 

     End If 
    End Sub 

    Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged 

    End Sub 


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
     If TextBox1.Text = "" Then 
      MsgBox("Please fill up all the information", MsgBoxStyle.Information) 
     ElseIf TextBox2.Text = "" Then 
      MsgBox("Please fill up all the information", MsgBoxStyle.Information) 
     ElseIf TextBox3.Text = "" Then 
      MsgBox("Please fill up your information", MsgBoxStyle.Information) 
     ElseIf TextBox4.Text = "" Then 
      MsgBox("Please fill up your information", MsgBoxStyle.Information) 
     ElseIf TextBox5.Text = "" Then 
      MsgBox("Please fill up your information", MsgBoxStyle.Information) 
     ElseIf TextBox6.Text = "" Then 
      MsgBox("Please fill up your information", MsgBoxStyle.Information) 
     ElseIf TextBox7.Text = "" Then 
      MsgBox("Please fill up all the information", MsgBoxStyle.Information) 
     ElseIf TextBox8.Text = "" Then 
      MsgBox("Please fill up all the information", MsgBoxStyle.Information) 
     ElseIf Split(Me.Text, " - ")(1) = "Add" Then 
      sqlSTR = "INSERT INTO BookRegister(ISBN, Title, Author, Volume, Pages, Publisher, Section, Year_Published) " & _ 
           "VALUES('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "'" & _ 
           ",'" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & ")""" 

      ExecuteSQLQuery(sqlSTR) 
      MsgBox("New record has been saved.", MsgBoxStyle.Information) 

      clear() 
     Else 
      sqlSTR = "UPDATE BookRegister SET ISBN ='" & TextBox1.Text & "', " & _ 
        "title='" & TextBox2.Text & "', " & _ 
        "author='" & TextBox3.Text & "', " & _ 
        "volume='" & TextBox4.Text & "', " & _ 
        "pages='" & TextBox5.Text & "', " & _ 
        "publisher='" & TextBox6.Text & "', " & _ 
        "section='" & TextBox7.Text & "', " & _ 
        "year_published='" & Format("yyyy", TextBox8.Text) & "', " & _ 
        " WHERE id =" & globalID 
      ExecuteSQLQuery(sqlSTR) 
      MsgBox("Record has been updated !!", MsgBoxStyle.Information) 
      clear() 
      globalID = 0 
      edit = False 
      Me.Close() 
     End If 
     FillListView(Form6.ListView1, ExecuteSQLQuery("select * from bookregister")) 
    End Sub 


    Private Sub clear() 
     Textbox1.Text = "" 
     TextBox2.Text = "" 
     TextBox3.Text = "" 
     TextBox4.Text = "" 
     TextBox5.Text = "" 
     TextBox6.Text = "" 
     TextBox7.Text = "" 
     TextBox8.Text = "" 


    End Sub 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
     Me.Close() 

    End Sub 
End Class 

回答

0

看起來你是在你的INSERT語句的末尾缺少一個最後的單引號,然後在右括號後追加外來雙引號,即

& "','" & TextBox8.Text & ")""" 

應該是

& "','" & TextBox8.Text & "')" 
相關問題