none
guid parameter in sqlcommand RRS feed

  • Question

  •  

    Hi,

     

    I have the following code that uses guid and is being used as a parameter in sql command. but i keep receiving an error : Incorrect syntax near 'a21c056'.

     

    Dim cn As SqlConnection

    Dim SQLCmd As SqlCommand

    Dim dr As SqlDataReader

    cn = New SqlConnection("Server=localhost;user=sa;pwd=157901;database=SONY_CS_PLATFORM")

    Dim varguid As Guid = New Guid("6a21c056-c75f-da11-a85e-0003ffd2a585")

    cn.Open()

    SQLCmd = New SqlCommand("select userkey from dim_t_user where userid = " & varguid.ToString, cn)

    dr = SQLCmd.ExecuteReader

    While dr.Read()

    MsgBox(dr(0).ToString)

    End While

     

    It might have caused data type mismatch on varguid.tostring.

     

    How can i convert it to guid?

     

    cherriesh

     

    Tuesday, July 24, 2007 12:22 AM

Answers

  • Hello
    Change the SQLCommand query to

    SQLCmd = New SqlCommand("select userkey from dim_t_user where userid = '" & varguid.ToString & "'", cn)
    Tuesday, July 24, 2007 9:15 AM