hi guys,

I got another issue doin my project. Im using Microsoft access as Database. When i need to UPDATE it work and the msgbox displayed: "thank you", but when i looked into the database nothing happened.

Anyone can help me to determine the problem? please
Thanks in advance.

   con.Open()
        Try

        sqlStr = "UPDATE TBValidation SET Time_OUT=@Time_OUT WHERE VTDriverID= ? AND VTDate=?             AND VTTime =?"
        cmd = New OleDb.OleDbCommand(sqlStr, con)
        cmd.Parameters.AddWithValue("@VTDriverID", txtscanbarcode.Text)
        cmd.Parameters.AddWithValue("@VTDate", txttripdate.Text)
        cmd.Parameters.AddWithValue("@VTTime", TimeString)
        cmd.Parameters.AddWithValue("@Timme_OUT", txttriptime.Text)
        cmd.ExecuteNonQuery()

        MessageBox.Show("Thank you")

    Catch ex As Exception
        MessageBox.Show("Error to Update:" & ex.Message, "error")
        Return
    End Try
    con.Close()

Try replacing "@Time_OUT" with "?" and make sure you do the AddWithValue calls in the same order in which the "?" appear in the query. When using OleDbCommand, the actual "@" strings in AddWithValue are ignored. The calls replace each "?" in turn no matter what "@Text" you specify.

I've try what you suggested but there's nothing happened.

Please post the new code. Silly question, but is the connection to the database open?

Im not sure about using the "AND"'s in your UPDATE statement there should be commas seperaing your fields and values. Here is a test query(StoredProcedure) I have in one of my access DB's. If you are going to be using this UPDATE query often you should create a stored procedure and add the parameters to the command in the order they appear in the stored procedure or the sql statements you write in vbCode.

ACCESS Stored Procedure Name = updateSong >>>

"UPDATE SONGS SET SONGS.TITLE = [?], SONGS.LOCATION = [?], SONGS.[SIZE] = [?]
    WHERE (((SONGS.ID)=[?]));"

<<<<

VB Code
title, location, size, and id are variables that are set by code

 Dim cmdUpdateSong As New OleDb.OleDbCommand()
        With cmdUpdateSong
            .CommandText = "updateSong"
            .CommandType = CommandType.StoredProcedure
            .Connection = conn

            .Parameters.AddWithValue("@title", title)
            .Parameters.AddWithValue("@location", location)
            .Parameters.AddWithValue("@size", size)
            .Parameters.AddWithValue("@id", id)
         End With

Also as Reverend Jim said you need to make sure you have an open and available Connection

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.