BioXhazard
BioXhazard

Reputation: 518

VB Mismatch Error

I keep getting a mismatch error for this line:

UPDATE tblLunchTime SET [End] = '06/28/2010 9:41:34 AM' WHERE Start = '06/28/2010 9:41:31 AM'

Does anyone know why?

EDIT: Rest of the code added.

'Save end time in database.
Dim strValuesQuery As String

strValuesQuery = _
    "UPDATE tblLunchTime " & _
    "SET [End] = '" & Now & "' " & _
    "WHERE Start = '" & StartTime & "' "

'Execute Query.
DoCmd.RunSQL strValuesQuery

Upvotes: 0

Views: 113

Answers (2)

x77
x77

Reputation: 737

Are you executing this query to SqlServer, oracle ?

Is same language at client side and server side ?

Using date To String and String to date needs a specific format conversion.

For oracle: EndTime = to_date('2010/01/05','yyyy/mm/dd')

this avoids language mismatch.

I use always parameters.

"UPDATE tblLunchTime SET EndTime = ? WHERE StartTime = ?" - For OleDb

Parameters avoid some errors, and also improve performance (Server caches cursors).

Upvotes: 0

BioXhazard
BioXhazard

Reputation: 518

I ended up adding the pound symbol to my variable in order to allow it to be formatted in the way needed:

strValuesQuery = _
    "UPDATE tblLunchTime " & _
    "SET EndTime = #" & Now & "# " & _
    "WHERE StartTime = #" & StartTime & "#"

Upvotes: 1

Related Questions