2011-08-03 4 views
0

저는 vb.net 2010을 사용하고 있습니다. 공급자는 OLEDB입니다. 내가 만든 탐색 단추를 통해 데이터베이스를 통과하는 vb.net을 사용하는 데이터베이스 프로그램을 만들고 있지만 Commit 또는 Update 단추를 누르면 다음 오류가 발생합니다. ERROR is {INSERT INTO 문에서 구문 오류입니다.} {dataadapter.Update (데이터 집합, "GRE 라이브러리")에서 두 단추 내의 두 위치에서 발생합니다
다른 모든 것은 제가 아는 한 잘 작동합니다. 나는 다른 형태를 가지고 있지만, 정말로 중요하거나 연관되어 있지 않습니다. 여기 오류 : "INSERT INTO 문의 구문 오류"

내 코드입니다 :

Public Class EditLibraryForm 

Dim MaxRows As Integer 
Dim inc As Integer 
Dim connection As New OleDb.OleDbConnection 
Dim databaseProvider As String 
Dim databaseSource As String 

Dim dataset As New DataSet 
Dim dataadapter As OleDb.OleDbDataAdapter 
Dim sql As String 

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

    databaseProvider = "Provider=Microsoft.ACE.OLEDB.12.0;" 
    databaseSource = "Data Source = H:\Game Revolutionaries Entertainment TEST2\Game Revolutionaries Entertainment\Resource\GRE Library.accdb" 
    connection.ConnectionString = databaseProvider & databaseSource 

    connection.Open() 
    sql = "SELECT * FROM [GRE Library Logistics]" 
    dataadapter = New OleDb.OleDbDataAdapter(sql, connection) 
    dataadapter.Fill(dataset, "GRE Library") 

    connection.Close() 

    MaxRows = dataset.Tables("GRE Library").Rows.Count 
    inc = -1 

End Sub 

Private Sub NavigateRecords() 

    txtname.Text = dataset.Tables("GRE Library").Rows(inc).Item(0).ToString 
    txtrating.Text = dataset.Tables("GRE Library").Rows(inc).Item(2).ToString 
    txtgenre.Text = dataset.Tables("GRE Library").Rows(inc).Item(3).ToString 
    txtplatform.Text = dataset.Tables("GRE Library").Rows(inc).Item(4).ToString 
    txtrd.Text = dataset.Tables("GRE Library").Rows(inc).Item(5).ToString 
    txtdc.Text = dataset.Tables("GRE Library").Rows(inc).Item(6).ToString 
    txtinfo.Text = dataset.Tables("GRE Library").Rows(inc).Item(7).ToString 
    txtpn.Text = dataset.Tables("GRE Library").Rows(inc).Item(8).ToString 
    txtsupport.Text = dataset.Tables("GRE Library").Rows(inc).Item(9).ToString 
    txtnews.Text = dataset.Tables("GRE Library").Rows(inc).Item(10).ToString 


End Sub 
Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click 

    If inc <> MaxRows - 1 Then 
     inc = inc + 1 
     NavigateRecords() 
    Else 
     MsgBox("No More items in Library") 
    End If 

End Sub 

Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprevious.Click 

    If inc > 0 Then 
     inc = inc - 1 
     NavigateRecords() 
    Else 
     MsgBox("This is First item") 
    End If 

End Sub 

Private Sub btnlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlast.Click 

    If inc <> MaxRows - 1 Then 
     inc = MaxRows - 1 
     NavigateRecords() 
    Else 
     MsgBox("Already on last item") 
    End If 

End Sub 

Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfirst.Click 

    If inc <> 0 Then 
     inc = 0 
     NavigateRecords() 
    Else 
     MsgBox("Already on first item") 
    End If 

End Sub 

Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click 

    Dim cb As New OleDb.OleDbCommandBuilder(dataadapter) 

    txtname.Text = dataset.Tables("GRE Library").Rows(inc).Item(0).ToString 
    txtrating.Text = dataset.Tables("GRE Library").Rows(inc).Item(2).ToString 
    txtgenre.Text = dataset.Tables("GRE Library").Rows(inc).Item(3).ToString 
    txtplatform.Text = dataset.Tables("GRE Library").Rows(inc).Item(4).ToString 
    txtrd.Text = dataset.Tables("GRE Library").Rows(inc).Item(5).ToString 
    txtdc.Text = dataset.Tables("GRE Library").Rows(inc).Item(6).ToString 
    txtinfo.Text = dataset.Tables("GRE Library").Rows(inc).Item(7).ToString 
    txtpn.Text = dataset.Tables("GRE Library").Rows(inc).Item(8).ToString 
    txtsupport.Text = dataset.Tables("GRE Library").Rows(inc).Item(9).ToString 
    txtnews.Text = dataset.Tables("GRE Library").Rows(inc).Item(10).ToString 



    dataset.Tables("GRE Library").Rows(inc).Item(0) = txtname.Text 
    dataset.Tables("GRE Library").Rows(inc).Item(2) = txtrating.Text 
    dataset.Tables("GRE Library").Rows(inc).Item(3) = txtgenre.Text 
    dataset.Tables("GRE Library").Rows(inc).Item(4) = txtplatform.Text 
    dataset.Tables("GRE Library").Rows(inc).Item(5) = txtrd.Text 
    dataset.Tables("GRE Library").Rows(inc).Item(6) = txtdc.Text 
    dataset.Tables("GRE Library").Rows(inc).Item(7) = txtinfo.Text 
    dataset.Tables("GRE Library").Rows(inc).Item(8) = txtpn.Text 
    dataset.Tables("GRE Library").Rows(inc).Item(9) = txtsupport.Text 
    dataset.Tables("GRE Library").Rows(inc).Item(10) = txtnews.Text 


    dataadapter.Update(dataset, "GRE Library") 
    MsgBox("Library updated") 

End Sub 

Private Sub btnaddnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddnew.Click 

    btncommit.Enabled = True 
    btnaddnew.Enabled = False 
    btnupdate.Enabled = False 
    btndelete.Enabled = False 

    txtname.Clear() 
    txtrating.Clear() 
    txtgenre.Clear() 
    txtplatform.Clear() 
    txtrd.Clear() 
    txtdc.Clear() 
    txtinfo.Clear() 
    txtpn.Clear() 
    txtsupport.Clear() 
    txtnews.Clear() 

End Sub 

Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click 

    btncommit.Enabled = False 
    btnaddnew.Enabled = True 
    btnupdate.Enabled = True 
    btndelete.Enabled = True 

    inc = 0 
    NavigateRecords() 

End Sub 

Private Sub btncommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncommit.Click 

    If inc <> -1 Then 

     Dim cb As New OleDb.OleDbCommandBuilder(dataadapter) 
     Dim datasetNewRow As DataRow 

     datasetNewRow = dataset.Tables("GRE Library").NewRow() 

     datasetNewRow.Item("Name") = txtname.Text 
     datasetNewRow.Item("PersonelRating") = txtrating.Text 
     datasetNewRow.Item("Genre") = txtgenre.Text 
     datasetNewRow.Item("Platform") = txtplatform.Text 
     datasetNewRow.Item("ReleaseDate") = txtrd.Text 
     datasetNewRow.Item("DevelopingCompany") = txtdc.Text 
     datasetNewRow.Item("GameInformation") = txtinfo.Text 
     datasetNewRow.Item("PersonalNotes") = txtpn.Text 
     datasetNewRow.Item("Support") = txtsupport.Text 
     datasetNewRow.Item("News") = txtnews.Text 


     dataset.Tables("GRE Library").Rows.Add(datasetNewRow) 

     dataadapter.Update(dataset, "GRE Library") 

     MsgBox("New item has been added to the library") 

     btncommit.Enabled = False 
     btnaddnew.Enabled = True 
     btnupdate.Enabled = True 
     btndelete.Enabled = True 

    End If 

End Sub 

Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click 


    Dim cb As New OleDb.OleDbCommandBuilder(dataadapter) 
    dataset.Tables("GRE Library").Rows(inc).Delete() 
    MaxRows = MaxRows - 1 

    inc = 0 
    NavigateRecords() 
    dataadapter.Update(dataset, "GRE Library") 

End Sub 
+0

commandBuilder에서 만든 insert 문을 게시 할 수 있습니까? – Muse

답변

2

당신은 당신이있을 수 있습니다 어떤 문제를 확인할 수 있도록 빌더 당신을 위해 만드는 것을 검색하고 화면에 표시 할 .GetInsertCommand().CommandText 방법을 & 속성을 사용할 수 있습니다 너의 방법으로.

+0

답장을 보내 주셔서 감사합니다. 오류가 발생하는 이유를 발견했습니다. 그 이유는 내 databse가 내 이미지에 사용하고있는 OLE 개체 필드를 가지고 있기 때문입니다. 내가 그것을 삭제 한 후, 프로그램은 잘 작동 했으므로, 나는 데이터를 추가하려고하는 whne을 추측한다. 그것은 특정 필드와 충돌한다. 그러나 문제는 내가 그 분야를 필요로한다, 어떻게해서든지 나는 계속 지킬 수있다 – Warchi

+0

@ Warchi : 그것은 멋지다. – Muse