Click here to Skip to main content
11,492,168 members (59,896 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
I have retrieved a value from database into session as
with query i got username from database into var p
then
session["username"]=p.ToString();

if i want to print the name into label
i write
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 6-Nov-12 19:04pm
Edited 6-Nov-12 19:15pm
v2
Comments
Neelam Chandra (8015059) at 7-Nov-12 0:08am
   
Which type of variable 'p' is? can u show the code u storing data in variable p?
Sanjay K. Gupta at 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.
Milind Thakkar at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Dee_Bee at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 550
1 Maciej Los 276
2 Sascha Lefèvre 265
3 Andy Lanng 249
4 F-ES Sitecore 230
0 Sergey Alexandrovich Kryukov 9,829
1 OriginalGriff 8,530
2 Sascha Lefèvre 3,579
3 Maciej Los 3,332
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100