Hi,

I seem to be getting the error "Syntax error in UPDATE statement." when attempting to update my database through visual studio 2008, using forms.

Here is the code for the connection:

Private Sub btnLoadDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadDB.Click

        Provider = "PROVIDER=MICROSOFT.ACE.OLEDB.12.0;"
        Source = "Data Source = F:\My Documents\Computing\COMP4\COMP4 CW\WND.accdb"

        connection.ConnectionString = Provider & Source

        connection.Open()

        sqlCode = "SELECT * FROM Newspapers"
        dAdapter = New OleDb.OleDbDataAdapter(sqlCode, connection)
        dAdapter.Fill(dSet, "Newspapers")

        MsgBox("Database Loaded.", MsgBoxStyle.Information)
        connection.Close()

        maxRows = dSet.Tables("Newspapers").Rows.Count
        incr = -1

    End Sub

The code for the update button on my form:

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        Dim cBuilder As New OleDb.OleDbCommandBuilder(dAdapter)

        dSet.Tables("Newspapers").Rows(incr).Item(0) = txtPMID.Text
        dSet.Tables("Newspapers").Rows(incr).Item(1) = txtPMName.Text
        dSet.Tables("Newspapers").Rows(incr).Item(2) = txtPMPrice.Text

        dAdapter.Update(dSet, "Newspapers")

        MsgBox("The record was successfully updated", MsgBoxStyle.Information)
    End Sub

Any help would be greatly appreciated.

Thanks

Collin

(p.s. I am using the following tutorial:

http://www.homeandlearn.co.uk/NET/nets12p9.html )

What is "cBuilder" doing for you?

What is "cBuilder" doing for you?

The cBuilder is the command builder; it builds the sql strings.

When is it being used?

When is it being used?

dAdapter.Update(dSet, "Newspapers")

In the above line. I'm sorry if I'm not being very clear, I'm a student, and I don't have the best teachers :(

Do you need to call

cBuilder.GetUpdateCommand()

right before calling the Update on the Adapter?

Do you need to call

cBuilder.GetUpdateCommand()

right before calling the Update on the Adapter?

I don't think I need to, no..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.