Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

VB 2008 - Access Syntax error UPDATE statement

$
0
0
Hi guys, I'm making a system where the user is able to log in, edit their account and etc.

Currently, I'm having trouble with trying to update the customer's account details such as their first name, surname and so on. The error I'm getting is an "OleDbException was unhandled - Syntax error in UPDATE statement" every time the program tries to execute the non-query code.

Below is my code:
Public Class EditCustAcc

    Dim EditAccConnect As New OleDb.OleDbConnection
    Dim EditAccSet As New DataSet
    Dim EditAccTable As New DataTable
    Dim EditAccAdapt As New OleDb.OleDbDataAdapter
    Dim EditAccBuilder As OleDb.OleDbCommandBuilder = Nothing
    Dim EditAccCommand As New OleDb.OleDbCommand
    Dim UpdateStr As String
    Dim CustIdentifier As Integer
    Dim Maxrows As Integer = -1

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

        Dim i As Integer

        If MainMenuForm.AccountStatus = True Then

            EditAccConnect.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Prototypeofthing\prototype.mdb"
            EditAccConnect.Open()

            EditAccSet.Tables.Add(EditAccTable)
            EditAccAdapt = New OleDb.OleDbDataAdapter("SELECT * FROM tblCustAcc", EditAccConnect)
            EditAccAdapt.Fill(EditAccTable)

            Try
                For i = 0 To EditAccTable.Rows.Count
                    If EditAccTable.Rows(i) Is Nothing Then
                    Else
                        Maxrows = Maxrows + 1
                    End If
                Next
            Catch ex As Exception
            End Try

            Try
                For i = 0 To Maxrows
                    If UCase(MainMenuForm.CustUsername) = UCase(EditAccTable.Rows(i).Item(1)) Then
                        CustIdentifier = EditAccTable.Rows(i).Item(0)
                        txtFirst.Text = EditAccTable.Rows(i).Item(3)
                        txtSur.Text = EditAccTable.Rows(i).Item(4)
                        txtHouseNum.Text = EditAccTable.Rows(i).Item(5)
                        txtHouseAdd.Text = EditAccTable.Rows(i).Item(6)
                        txtPostCode.Text = EditAccTable.Rows(i).Item(7)
                        txtEmailAdd.Text = EditAccTable.Rows(i).Item(8)
                        Exit For
                    End If
                Next
            Catch ex As Exception
            End Try

            EditAccConnect.Close()

        End If

    End Sub

    Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click

        EditAccConnect.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Prototypeofthing\prototype.mdb" 'Directory to databse'
        EditAccConnect.Open() 'Opens the link to the database'

        EditAccAdapt = New OleDb.OleDbDataAdapter("SELECT * FROM tblCustAcc", EditAccConnect)
        EditAccAdapt.Fill(EditAccTable)

        For i = 0 To Maxrows
            If UCase(MainMenuForm.CustUsername) = UCase(EditAccTable.Rows(i).Item(1)) Then
                UpdateStr = "UPDATE tblCustAcc SET ([First Name] =" & txtFirst.Text & ") WHERE CustomerID =" & CustIdentifier & ")"
                EditAccCommand = New OleDb.OleDbCommand(UpdateStr, EditAccConnect)
                EditAccCommand.ExecuteNonQuery() 'This is the part where the code stops working
                EditAccCommand.Connection.Dispose()
                Exit For
            End If
        Next

    End Sub
End Class



The methods I've used have been:
Parameters
[ ] Square Brackets as shown in the code
A few other minor methods which I don't remember exactly

The methods pretty much still gave me a Syntax error with the Update statement. I'm not exactly certain what might be causing this and therefore I wondered if anyone would be able to help me spot it out, thanks!

Viewing all articles
Browse latest Browse all 51036

Trending Articles