0
Public Class Form4

Dim sql As String                                   'Declaring sql as a string
Dim con As New OleDb.OleDbConnection                'Declaring con as a new connection
Dim da As OleDb.OleDbDataAdapter                    'Declaring da as a data adapter
Dim ds As New DataSet                               'Declaring ds as a new data set
Dim Inc As Integer                                  'Declaring inc As an integer
Dim Maxrows As Integer                              'Declaring maxrows as an integer

'inside of the connection, i have to fill the dataset, and then fill the adapter with the dataset
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    con.ConnectionString = "PROVIDER = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Users\MadMaxHarl\Desktop\Thespellingbee\Resources\Spelling Bee1.mdb"   'States where the database is, as well as the provider
    con.Open()                                          'Opens the connection
    sql = "SELECT * FROM [WordsDefinitions] [WD]"       'The sql string is filled with the data from the table "Words + Definitions"
    da = New OleDb.OleDbDataAdapter(sql, con)           'Makes da a new data adapter containing the connection and the sql string
    da.Fill(ds, "WD")
    con.Close()                                         'Closes the connection
    Maxrows = ds.Tables("WD").Rows.Count
    Inc = -1
End Sub

Private Sub navigaterecords()
    txtword.Text = ds.Tables("WD").Rows(Inc).Item(1)
    Txtdescription.Text = ds.Tables("WD").Rows(Inc).Item(2)
End Sub

Private Sub BtnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBack.Click
    If inc > 0 Then
        Inc = Inc - 1
        navigaterecords()
    Else
        MsgBox("First Record")
    End If
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 Rows")
    End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    If Inc <> Maxrows - 1 Then
        Inc = Maxrows - 1
        navigaterecords()
    End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    If Inc <> 0 Then
        Inc = 0
        navigaterecords()
    End If
End Sub

Private Sub BtnExitSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExitSave.Click
    Dim cb As New OleDb.OleDbCommandBuilder(da)         'Command builder needed to change database, stored data adapter in the variable cb

    ds.Tables("WD").Rows(Inc).Item(1) = txtword.Text
    ds.Tables("WD").Rows(Inc).Item(2) = Txtdescription.Text

    da.Update(ds, "WD")

    MsgBox("It's working", MessageBoxButtons.OK)
End Sub

End Class

所以在这段代码的最后,我得到一个巨大的语法错误,指出“查询表达式中的语法错误(缺少运算符)'((Word Number = ?) AND ((? = 1 AND Word IS NULL) OR (Word = ?)) AND ((? = 1 AND Description IS NULL) OR (Description = ?)))'."

有人有什么想法吗?

编辑:好的,这个错误就在 da.update 的最后

2:我的 sql 试图连接的东西是一个看起来像这样的数据库:

   Word Number  Word    Description
   1        Hectare         Unit Of Area
   2        Active          Being Busy
   3        Amaze           Surprise
    4       Bound           Leap And Jump
   5        Cavern          A Large Cave
   6        Difficult           Hard To Do
   7        Frozen          Turned To Ice
   8        Garage          Building For A Car
   9        Jaguar          Large Cat
   10       Lemonade            Fizzy Drink
4

0 回答 0