convert string variable to uniqueidentifier

G

Guest

I'm building a SQL String and I want to choose only the records that are part of the current contractID.

My Variable
Dim contrID = Request.Params("oId"

I put it into the SQL String
WHERE (JS_CRM.dbo.cntrct_cntct.ContractId = '" & contrID & "')

And I get the error message
Syntax error converting from a character string to uniqueidentifier

How do I convert my string to a uniqueidentifier???

Thanks
 
J

Jeremy Cowles

Sandy said:
I'm building a SQL String and I want to choose only the records that are
part of the current contractID.
My Variable:
Dim contrID = Request.Params("oId")

I put it into the SQL String:
WHERE (JS_CRM.dbo.cntrct_cntct.ContractId = '" & contrID & "')
And I get the error message:
Syntax error converting from a character string to uniqueidentifier.

Is ContractId a GUID? If so, I don't think you need the single quotes around
your variable. If that's not the issue, then you need to check the value of
contrID to make sure it is in fact a valid GUID.

HTH
-
Jeremy
 
J

Jeremy Cowles

Another possiblity is that you need to setup your SqlParamater properly,
giving it a SqlType = UniqueIdentifier.
 
J

Jeremy Cowles

Jeremy Cowles said:
Another possiblity is that you need to setup your SqlParamater properly,
giving it a SqlType = UniqueIdentifier.

Looks like you're not using Parameters, so scratch that.
 
G

Guest

Hi Jeremy, thanks for responding. You are correct, contactId is a GUID. I removed the single quotes and the error message said Incorrect Syntax.

If you have any other ideas that would be great!

I tried using, but it said couldn't convert string to SqlGuid:

Public Function Parse(ByVal s As String) As SqlGuid

Return s
End Function
 
J

Jeremy Cowles

Sandra said:
Hi Jeremy, thanks for responding. You are correct, contactId is a GUID.
I removed the single quotes and the error message said Incorrect Syntax.

So if you step through the code, is the value of your string variable infact
a GUID? I am willing to bet that it is empty or missing part of the GUID.
 
G

Guest

I actually did a Response.Write(myvariable) to output the variable at the top of the screen so I could see what it is putting in there. It displays exactly as it should be: {F4B7FBB9-29A3-4E22-B778-19CCDAAEBB4F

If I replace my variable with that exact output, it works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top