Using variable from Code-behind in SQL Query, asp.net C#

Posted by Carl on Stack Overflow See other posts from Stack Overflow or by Carl
Published on 2010-04-26T13:16:01Z Indexed on 2010/04/26 15:33 UTC
Read the original article Hit count: 669

Filed under:
|
|
|

I am trying to use a variable from the code-behind page in a sqlDataSource WHERE statement. I am using Membership.GetUser().ProviderUserKey to obtain the UserId of the logged in user and I would like to only show record that have this UserId as a foreign key. How can I write the SQL for this?

Thanks much, Carl

Here is what I have so far:

SQL Query:

SelectCommand="SELECT [UserID], [CarID], [Make], [Model], [Year] FROM [Vehicle]"

Code-Behind

String user2 = ((Guid)Membership.GetUser().ProviderUserKey).ToString();

And I want to add WHERE UserID = user2 to the SQL Query.

© Stack Overflow or respective owner

Related posts about sql

Related posts about query