Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have retrieved a value from database into session as
with query i got username from database into var p
then
C#
session["username"]=p.ToString();


if i want to print the name into label
i write
C#
label.Text=session["username"].ToString();

it should print only username but it is printing column name too(like {username=aman})
what should i do?
remember i'm getting value from database
Posted
Updated 6-Nov-12 18:15pm
v2
Comments
NAPorwal(8015059) 7-Nov-12 0:08am    
Which type of variable 'p' is? can u show the code u storing data in variable p?
[no name] 7-Nov-12 0:34am    
m using entity framwork i used query as var p=from temp in Tbl_Member where (temp .member_email_id == txtUsername.Text.Trim()) orderby temp .member_id select new { temp .member_first_name }; foreach (var usename in p) { Session["username"] = usename .ToString(); Label1.Text = Session["username"].ToString(); }
[no name] 7-Nov-12 0:16am    
m using entity framwork
i used query as
var p=from temp in Tbl_Member
where (temp .member_email_id == txtUsername.Text.Trim())
orderby temp .member_id
select new { temp .member_first_name };
foreach (var usename in p)
{

Session["username"] = usename .ToString();
Label1.Text = Session["username"].ToString();
}
Sanjay K. Gupta 7-Nov-12 0:17am    
store this way value in session
session["username"]=p["UserName"].ToString();
I thing you are storing the "DataRowView" object in session.
MT_ 7-Nov-12 0:23am    
Why you reposting questions with same subject http://www.codeproject.com/Questions/489669/sessionplusvalueplusretrievel

If the question is different, atleast change subject appropriately. This confuses members.

1 solution

string str = session["username"].ToString();
str = str.Remove(0,9);
label.Text= str;


It removes 'username=' and displays only the text 'aman'.
Hope you can use remove function and (0,9) as 'username=' is same for every data base call here in your program.
 
Share this answer
 
Comments
[no name] 7-Nov-12 5:44am    
this doesn't work
Dee_Bee 7-Nov-12 23:23pm    
did you try this ?

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