By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,220 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,220 IT Pros & Developers. It's quick & easy.

convert string variable to uniqueidentifier

P: n/a
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

Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Sandy" <an*******@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.com...
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

Nov 20 '05 #2

P: n/a
Another possiblity is that you need to setup your SqlParamater properly,
giving it a SqlType = UniqueIdentifier.

Nov 20 '05 #3

P: n/a
"Jeremy Cowles" <jeremy.cowles[nosp@m]asifl.com> wrote in message
news:sS*******************@twister.tampabay.rr.com ...
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.
Nov 20 '05 #4

P: n/a
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
Nov 20 '05 #5

P: n/a
"Sandra" <an*******@discussions.microsoft.com> wrote in message
news:AA**********************************@microsof t.com...
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.

Nov 20 '05 #6

P: n/a
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.
Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.