Using a guid in a SQL SELECT statement

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
jui2ceAsked:
Who is Participating?
 
jvn222Connect With a Mentor Commented:
try
...UserID = '" & CType(Session("SessionUID"), Guid).ToString()& "'"
0
 
technixrsCommented:
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
 
jui2ceAuthor Commented:
Now I get Conversion failed when converting from a character string to uniqueidentifier.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
jvn222Commented:
please show your full statement that include string SELECT count(PhotoId) AS imagecount FROM Photos WHERE UserID = '" & Session("SessionUID") & "'"
0
 
jui2ceAuthor Commented:
Sorry the error I get now is

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

The problem before was session expired

0
 
jui2ceAuthor Commented:
I fixed it by doing  Session("SessionUID").ToString
0
 
jui2ceAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.