Imports System.Data.OleDb
Public Class Form1
Dim pro As String
Dim connstring As String
Dim myconnection As OleDbConnection = New OleDbConnection
Dim command As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    pro = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sinthu\Documents\Database1.accdb"
    connstring = pro
    myconnection.ConnectionString = connstring
    myconnection.Open()
    If myconnection.State = ConnectionState.Open Then
        MsgBox("connected")
    End If
    command = "UPDATE[Table1]SET[JOBNO]='" & TextBox2.Text & "',[LABNO]='" & TextBox3.Text & "',WHERE[ID]='" & TextBox1.Text & "'"
    Dim cmd As OleDbCommand = New OleDbCommand(command, myconnection)
    Try
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        myconnection.Close()
        TextBox2.Clear()
        TextBox3.Clear()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    myconnection.Close()
End Sub

End Class

Recommended Answers

All 9 Replies

can anyone help me the above statement when run shows "syntax error in update statment"

Your problem is in

command = "UPDATE[Table1]SET[JOBNO]='" & TextBox2.Text & "',[LABNO]='" & TextBox3.Text & "',WHERE[ID]='" & TextBox1.Text & "'"

How are we supposed to help you without knowing the values of the textbox controls? Please output the resulting value of command and post it here.

The thread 'vshost.LoadReference' (0x29d8) has exited with code 0 (0x0).
'UPDATE_TRIAL.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\sinthu\Documents\RECIPE_DATA2020\UPDATE_TRIAL\UPDATE_TRIAL\bin\Debug\UPDATE_TRIAL.exe', Symbols loaded.
'UPDATE_TRIAL.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'UPDATE_TRIAL.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'
'UPDATE_TRIAL.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0
b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'UPDATE_TRIAL.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'UPDATE_TRIAL.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
The thread 'vshost.RunParkingWindow' (0x16a0) has exited with code 0 (0x0).
The thread '' (0x2788) has exited with code 0 (0x0).
The program '[7028] UPDATE_TRIAL.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[7028] UPDATE_TRIAL.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

Imports System.Data.OleDb
Public Class Form1
Public pro As String
Public connstring As String
Public myconnection As OleDbConnection = New OleDbConnection
Public command As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    pro = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sinthu\Documents\Database1.accdb"
    connstring = pro
    myconnection.ConnectionString = connstring
    myconnection.Open()
    If myconnection.State = ConnectionState.Open Then
        MsgBox("connected")
    End If
    Dim JOB As Integer = TextBox2.Text
    Dim LAB As Integer = TextBox3.Text
    Dim ID As Integer = TextBox1.Text

    command = "UPDATE[Table1]SET[JOBNO]='" & JOB & "',[LABNO]='" & LAB & "',WHERE[ID]='" & ID & "'"
    Dim cmd As OleDbCommand = New OleDbCommand(command, myconnection)

    cmd.Parameters.AddWithValue("JOBNO", JOB)
    cmd.Parameters.AddWithValue("LABNO", LAB)
    Try
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        myconnection.Close()
        TextBox2.Clear()
        TextBox3.Clear()

    Catch ex As Exception
        MsgBox(ex.Message)

    End Try
    myconnection.Close()

End Sub

above statements also making similar "update syntax error" occurs

Imports System.Data.OleDb
Public Class Form1
Public pro As String
Public connstring As String
Public myconnection As OleDbConnection = New OleDbConnection
Public command As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    pro = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sinthu\Documents\Database1.accdb"
    connstring = pro
    myconnection.ConnectionString = connstring
    myconnection.Open()
    If myconnection.State = ConnectionState.Open Then
        MsgBox("connected")
    End If
    Dim JOB As Integer = TextBox2.Text
    Dim LAB As Integer = TextBox3.Text
    Dim ID As Integer = TextBox1.Text

    command = "UPDATE[Table1]SET[JOBNO]='" & JOB & "',[LABNO]='" & LAB & "',WHERE[ID]='" & ID & "'"
    Dim cmd As OleDbCommand = New OleDbCommand(command, myconnection)

    cmd.Parameters.AddWithValue("JOBNO", JOB)
    cmd.Parameters.AddWithValue("LABNO", LAB)
    Try
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        myconnection.Close()
        TextBox2.Clear()
        TextBox3.Clear()

    Catch ex As Exception
        MsgBox(ex.Message)

    End Try
    myconnection.Close()

End Sub

And yet you still won't tell us what the query string is.

commented: could it be as simple as a space before the word SET: command = "UPDATE[Table1]SET[JOBNO]='" & JOB & "',[LABNO]='" & LAB & +0

No comma before where in SQL.

No comma before where in SQL.

That's likely it but as a rule I like to see the actual query. I find it hard to visually scan a line that has multiple brackets, variables, concatenators and single and double quotes and other delimeters.

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.