Solved

Using a guid in a SQL SELECT statement

Posted on 2006-06-11
7
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

734 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