Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a master page in master page have a login and logout session this session named is session["user"] .

i want to use session["user"] in query for a label message print.

What I have tried:

SqlCommand cmd = new SqlCommand("select id_users from users where usermail=@user ", con);
        cmd.Parameters.AddWithValue("@user",Session["user"]);
Posted
Updated 17-Jan-17 17:38pm
v3
Comments
[no name] 10-Jan-17 20:47pm    
And? Do you have an actual question?
Afzaal Ahmad Zeeshan 11-Jan-17 9:36am    
Never mind.
Richard Deeming 11-Jan-17 12:11pm    
What's wrong with the code you posted? Do you get an error?
Maciej Los 12-Jan-17 3:02am    
Can you be more specific than that: "i want to use session["user"] in query for a label message print."? Your code is irrelevant to your question.

try this

int userID = Convert.ToInt32(HttpContext.Current.Session["UserID"]);
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 11-Jan-17 9:35am    
Never mind.
Richard Deeming 11-Jan-17 12:09pm    
Where?

Maybe I'm going blind, but I've looked at all revisions of the question, and I can't see any mention of jQuery.
Afzaal Ahmad Zeeshan 11-Jan-17 12:10pm    
I mistook SQL query for jQuery. -_- Sorry.
Richard Deeming 11-Jan-17 12:11pm    
Easily done. :)
Member 12677198 11-Jan-17 11:24am    
i improved my question please read it again
After logging to the application if you store user info in the session variable like Session["User"] = "UserName" then you can access this session variable through out the page.
So if you want to print in user information in the page then you can use this syntax.

lblID.text= Convert.Tostring(Session["User"]);

If You want to pass to the sql server as per your example.

SqlCommand cmd = new SqlCommand("select id_users from users where usermail=@user ", con);
cmd.Parameters.AddWithValue("@user",Convert.Tostring(Session["User"]));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900