Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using a guid in a SQL SELECT statement

Posted on 2006-06-11
7
Medium Priority
?
363 Views
Last Modified: 2008-02-01
I am trying to do a search for records in SQL that have a userID of the current logged in user. I have set the SessionUID to the GUID of the user logged in. When I use this select statment I get

Operator '&' is not defined for string " SELECT count(PhotoId) AS imagec" and type 'Guid'.


 SELECT count(PhotoId) AS imagecount FROM Photos WHERE UserID = '" & Session("SessionUID") & "'"

Please help
Thanks
0
Comment
Question by:jui2ce
  • 4
  • 2
7 Comments
 

Expert Comment

by:technixrs
ID: 16883026
SELECT count(PhotoId) AS imagecount FROM Photos WHERE UserID = '" & CType(Session("SessionUID"), String) & "'"

Also try using "Option Strict" to catch this in the future
0
 

Author Comment

by:jui2ce
ID: 16883031
Now I get Conversion failed when converting from a character string to uniqueidentifier.
0
 
LVL 4

Expert Comment

by:jvn222
ID: 16883072
please show your full statement that include string SELECT count(PhotoId) AS imagecount FROM Photos WHERE UserID = '" & Session("SessionUID") & "'"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jui2ce
ID: 16883078
Sorry the error I get now is

Conversion from type 'Guid' to type 'String' is not valid.

The problem before was session expired

0
 
LVL 4

Accepted Solution

by:
jvn222 earned 2000 total points
ID: 16883131
try
...UserID = '" & CType(Session("SessionUID"), Guid).ToString()& "'"
0
 

Author Comment

by:jui2ce
ID: 16883134
I fixed it by doing  Session("SessionUID").ToString
0
 

Author Comment

by:jui2ce
ID: 16883135
Thanks!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question