Using variable from Code-behind in SQL Query, asp.net C#
- by Carl
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.