-3

I'm having trouble updating my records. I don't know what seems to be the problem. After clicking update no error seems to be appearing. Here is my code.

    conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Charles\Documents\Database1.accdb"
    Dim cmd As String
    cmd = "UPDATE Employee SET EmployeeName = @eName, SSS = @SSS, TIN = @TIN, ED = @ED, Salary = @Salary WHERE EmployeeName = @eName"
    Dim cmdUpdate As New OleDbCommand(cmd, conn)

    enableTxtBox()
    If btnEdit.Text = "Edit" Then
        btnEdit.Text = "Update"
    Else
        btnEdit.Text = "Edit"

        Try
            conn.Open()
            cmdUpdate.Parameters.AddWithValue("@eName", txtName.Text)
            cmdUpdate.Parameters.AddWithValue("@SSS", txtSSS.Text)
            cmdUpdate.Parameters.AddWithValue("@TIN", txtTIN.Text)
            cmdUpdate.Parameters.AddWithValue("@ED", dtpED)
            cmdUpdate.Parameters.AddWithValue("@Salary", txtSalary.Text)
            cmdUpdate.ExecuteNonQuery()

            fillListView()
            clearAll()
            disableTxtBox()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        conn.Close()
    End If
2
  • You're saying that the UPDATE failed, yet you claim that no error is reported anywhere. So how do you know that it failed? Sep 13, 2014 at 6:57
  • sorry, i was on vacation last weekend so i wasn't able to reply... as you can see i tried to catch if any errors will occur.. "BUT" upon editing a certain record, that record doesn't seem to be updating... but no errors are showing so i really don't know what code im missing
    – NewbieVB
    Sep 15, 2014 at 1:20

1 Answer 1

0
cmdUpdate.Parameters.AddWithValue("@ED", dtpED)

Assuming that dtpED is a DateTimePicker control, you probably want to set that parameter to dtpED.Value (i.e. the date selected in the control), not to the dtpED control itself:

cmdUpdate.Parameters.AddWithValue("@ED", dtpED.Value)
                                             '^^^^^^'

By the way, I am assuming here that the cmdUpdate.ExecuteNonQuery() statement is actually reached and executed. That is not clear from your answer, due to the conditional check of btnEdit.Text. (If that button is labelled Edit, you will have to run your code twice to get to the command execution code, because once you're inside the Then clause, the Else clause will always be skipped, even if you change btnEdit.Text, which was part of the If condition.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.