"Syntax error converting datetime from character string"
i get this error when i am trying to pass 2 dates as parameters to a stored procedure in sql server
thanks for any help in advance
Printable View
"Syntax error converting datetime from character string"
i get this error when i am trying to pass 2 dates as parameters to a stored procedure in sql server
thanks for any help in advance
It would be better if you would post your code.
dates to a data base have to be in specific format, for access it is mm/dd/yy
i am not sure about sql, maybe the same or maybe yyyy/mm/dd
pete
.Parameters.Append .CreateParameter("@DateFrom", adVarChar, adParamInput, 25, CStr(MyArgs(1)))
.Parameters.Append .CreateParameter("@DateTo", adVarChar, adParamInput, 25, CStr(MyArgs(2)))
'Setup connection details and open connection to dB
Set mycon = New ADODB.Connection
mycon.ConnectionString = "File Name=" & App.Path & UDL_FILENAME
mycon.Open
Set .ActiveConnection = mycon
'Run command
.Execute
no matter how i pass these variables, i am getting the same error.
i mean i tried with the parameter datatype as adDate. no luck
What is CStr(MyArgs(2))?
date selected by the user from a datepicker
Why are you converting them to string with CSTR?
i am just trying various combinations.............
even if i send the parameters as it is (with out converting) still i am getting the same error
What type does the stored procedure use for the input parameters?
If possible, just change them to DateTime, so you can pass the parameters as dates, and not as text.
Your code needs a change too.
VB Code:
.Parameters.Append .CreateParameter("@DateFrom", adDate, adParamInput, 25, MyArgs(1)) .Parameters.Append .CreateParameter("@DateTo", adDate, adParamInput, 25, MyArgs(2))
well i tried that. didnt work. still the same error
Can you post the code of the stored procedure?
finally, resolved. Thank you everybody for your help & time.