problems with type conversion...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brad Pears

    #1

    problems with type conversion...

    I am using a function called "CreateSQLParam " which adds SQL parameters to a
    collection.

    The function is shown below... I add a parameter to a collection using the
    following line code...

    dim colParms as collection

    ' Add a paramter to the collection
    colParms.Add(Cr eateSQLParam("@ vcContractNo", ContractNo, SqlDbType.VarCh ar,
    ParameterDirect ion.Input)

    I am getting an error on the "ContractNo " field in the above line that says
    "option strict on disallows narrowing from type "object" to type "string"
    in copying teh value of ByRef parameter "sValue" back to the matching
    argument
    Here is the function...

    Function CreateSQLParam( ByVal sName As String, ByRef sValue As Object, ByVal
    varType As System.Data.Sql DbType, ByVal varDir As ParameterDirect ion) As
    SqlClient.SqlPa rameter

    Dim objParam As SqlClient.SqlPa rameter

    objParam = New SqlClient.SqlPa rameter()

    objParam.Parame terName = sName

    If IsNothing(sValu e) Then sValue = System.DBNull.V alue

    objParam.Value = sValue

    objParam.SqlDbT ype = varType

    objParam.Direct ion = varDir

    CreateSQLParam = objParam

    End Function


    Can someone help me out with what I need to do to get this working
    properly??

    Thanks, Brad


  • Armin Zingler

    #2
    Re: problems with type conversion...

    "Brad Pears" <bradp@truenort hloghomes.comsc hrieb
    I am using a function called "CreateSQLParam " which adds SQL
    parameters to a collection.
    >
    The function is shown below... I add a parameter to a collection
    using the following line code...
    >
    dim colParms as collection
    >
    ' Add a paramter to the collection
    colParms.Add(Cr eateSQLParam("@ vcContractNo", ContractNo,
    SqlDbType.VarCh ar, ParameterDirect ion.Input)
    >
    I am getting an error on the "ContractNo " field in the above line
    that says "option strict on disallows narrowing from type "object" to type
    "string" in copying teh value of ByRef parameter "sValue"
    back to the matching argument
    Here is the function...
    I guess "ContractNo " is declared as String. What if sValue returns
    System.DBNull.V alue? It could not be stored in a string variable. If you
    don't want sValue to return a value, declare it ByVal.


    Armin

    Comment

    Working...