Syntax error converting the varchar value...

  • It looks like your parameter mapping in the call top the stored procedure is wrong and it is trying to put the text into a parameter defined as Int - can you post the stored procedure and the code you are using to call it?

    If you are instantiating and ADODB.Command object, then appending parameters to the object, these are passed by position, and not by name:

    Here is an example:

    Set cmd = New ADODB.Command

    cmd.ActiveConnection = CurrentProject.Connection

    cmd.CommandText = "spUPCalendar"

    cmd.CommandType = adCmdStoredProc

    Set prm = cmd.CreateParameter("@DateUpdated", adDate, adParamInput, , Format(Now(), "dd/mm/yyyy"))

    cmd.Parameters.Append prm

    Set prm = cmd.CreateParameter("@UpdatedBy", adVarChar, adParamInput, 10, LoginID)

    cmd.Parameters.Append prm

    cmd.Execute

    Set cmd = Nothing

    Set prm = Nothing

    CREATE PROCEDURE spUPCalendar

    ( @DateUpdated [datetime], @UpdatedBy [varchar](10))

    AS UPDATE tblCalendar

    SET

    [DateUpdated] = @DateUpdated,

    [UpdatedBy] = @UpdatedBy

    GO

    If you create the parameters in a different order, it doesn't matter what the name is - the first defined parameter object gets passed to the first parameter in the SP defiinition, and subsequent ones to the ones in the equivalent position - eg:

    Set cmd = New ADODB.Command

    cmd.ActiveConnection = CurrentProject.Connection

    cmd.CommandText = "spUPCalendar"

    cmd.CommandType = adCmdStoredProc

    Set prm = cmd.CreateParameter("@UpdatedBy", adVarChar, adParamInput, 10, LoginID)

    cmd.Parameters.Append prm

    Set prm = cmd.CreateParameter("@DateUpdated", adDate, adParamInput, , Format(Now(), "dd/mm/yyyy"))

    cmd.Parameters.Append prm

    cmd.Execute

    Set cmd = Nothing

    Set prm = Nothing

    Here DateUpdated will be passed to the UpdatedBy parameter, and UpdatedBy will be passed to the DateUpdated parameter.

    If you change your code to the following, it is passed by name, and not by position - the Parameters.Refresh brings back the parameters from the server and you can then refer to them by name, and you don't have to specify the data type etc :

    Set cmd = New ADODB.Command

    cmd.ActiveConnection = CurrentProject.Connection

    cmd.CommandText = "spUPCalendar"

    cmd.CommandType = adCmdStoredProc

    cmd.Parameters.Refresh

    cmd.Parameters("@UpdatedBy")= LoginID

    cmd.Parameters("@DateUpdated") = Format(Now(), "dd/mm/yyyy"))

    cmd.Execute

    Set cmd = Nothing

  • Many thanks for you reply.

    I have just tracked down the source of the error - and it turned out to be another stored procedure, which was processing the string. The second sp uses CHARINDEX to parse the string - and it was failing as soon as the string was > 8000. (BOL doesn't appear to mention this limitation!)

Viewing 2 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply