dbTalk Databases Forums  

uniqueidentifier query

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss uniqueidentifier query in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Suraj Shah
 
Posts: n/a

Default uniqueidentifier query - 04-15-2010 , 01:53 PM






hi there. i need some help with a query please. my table has two
fields:

family_id {identity} - uniqueidentifier

family_name - nvarchar

I have a query in my ASP.NET code (in VB.NET) that should compare a
family_id as supplied by the user as a string with the family_id in
the table and output the corresponding family_name.

My query is as follows:

Dim UserID As String = New
String(Membership.GetUser(User.Identity.Name).Prov iderUserKey.ToString())

Dim queryString As String = "SELECT family_name FROM tblFamily WHERE '
& [family_id] & ' = ' & UserID & ' ;"

The problem is, that whenever I execute this, it never returns
anything.

Thanks in advance for any help you can give me.

Reply With Quote
  #2  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: uniqueidentifier query - 04-15-2010 , 04:58 PM






The best solution to this problem is to use a parameterized query. See one example here (in the Parameterization section):
http://pratchev.blogspot.com/2009/03/sql-injection.html

To use the code as you have it you can enclose the value in single quotes:

Dim queryString As String = "SELECT family_name FROM tblFamily WHERE family_id = '" & UserID & "';"


--
Plamen Ratchev
http://www.SQLStudio.com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.