im having a problem on double execution, this is a part of audit trail on my system, the DELETE FUNCTION is working, but it aint updating, im getting an error - it says that "Syntax Error on update statement" on i tried to manually query it on my access and it is working

Dim burahin As String
        burahin = MsgBox("Are you sure you want to delete a customer from the database", vbOKCancel + vbQuestion, "Administrator")
        If burahin = vbOK Then
            Dim delet = "UPDATE audit SET action= 'DELETED A CUSTOMER' WHERE pk_id = " + TextBox5.Text + ""
            Dim Sql = "Delete from customer where  customer_ID= " + TextBox1.Text + ""
            cmd = New OleDbCommand(Sql, connection)
            cmd2 = New OleDbCommand(delet, connection)
            Dim affectedRecord As Integer
            [b]Dim affectedRecord2 As Integer[/b]
            Try
                connection.Open()
                affectedRecord = cmd.ExecuteNonQuery

                If affectedRecord = 0 Then
                    MessageBox.Show("No Record was Updated")
                Else
                    MsgBox("Customer Deleted", MsgBoxStyle.Information, "Administrator")
                    Call textdb2clear()

                    DataGridView1.DataSource = Nothing
                    sql2.Fill(db1, "customer")
                    DataGridView1.DataSource = db1.Tables(0)
                End If
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
            connection.Close()
            connection.Open()
            Try
                affectedRecord2 = cmd2.ExecuteNonQuery
                If affectedRecord2 = 0 Then
                    MessageBox.Show("No Record was Updated")
                End If
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
            If connection.State <> ConnectionState.Closed Then
                connection.Close()
            End If
        End If

Try the following with your update statement -

Dim delet = "UPDATE audit SET action = '[DELETED A CUSTOMER]' WHERE pk_id = '" + TextBox5.Text + "'"

Have a look at This link. It might help solve your problem.

It sounds like a naming convention or reserved word used in the update statement.

i dont see anything wrong with it, there is no reserved word here

"UPDATE audit SET action= 'DELETED A CUSTOMER' WHERE pk_id = " + TextBox5.Text + ""

Edited 6 Years Ago by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

wtf action

Keep It Pleasant - Do not use offensive or obscene language

If you have question ask in polite way or I'm sure nobody will reply to your posts. So hurry up and apologise

This article has been dead for over six months. Start a new discussion instead.