Solved

Using a guid in a SQL SELECT statement

Posted on 2006-06-11
7
329 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 500 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

829 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