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
Who is Participating?
jvn222Connect With a Mentor Commented:
...UserID = '" & CType(Session("SessionUID"), Guid).ToString()& "'"
SELECT count(PhotoId) AS imagecount FROM Photos WHERE UserID = '" & CType(Session("SessionUID"), String) & "'"

Also try using "Option Strict" to catch this in the future
jui2ceAuthor Commented:
Now I get Conversion failed when converting from a character string to uniqueidentifier.
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.

please show your full statement that include string SELECT count(PhotoId) AS imagecount FROM Photos WHERE UserID = '" & Session("SessionUID") & "'"
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

jui2ceAuthor Commented:
I fixed it by doing  Session("SessionUID").ToString
jui2ceAuthor Commented:
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.