Click here to Skip to main content
15,905,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi friends,

am working on asp.net c#, Sqlserver 2005.

i want to display Firstname and last name of user using label

----------

I have login page, in this i have username and password to login,

on welcome page i have label to display login username.

for example my login username is rahman

and in my database i have my First name as Mohammed and Last name as Rahman

now after login i want to display in welcome page as
Welcome Mr. Mohammed Rahman (FirstName and LastName)

Please help thanks.
Posted

I assume you are a beginner. Going to suggest you simplest way so you can get idea how to deal with this type of stuffs.

C#
SqlConnection conn = new SqlConnection();
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionstring name"].ConnectionString;
conn.Open();
SqlCommand cmd = new SqlCommand("select query for firstname lastname",conn);//advised to use parameterized query
SqlDataReader dr = cmd.ExecuteReader();
if(dr.read)
{
    yourlabel.text="Welcome, Mr." + dr.GetString(0)+" "+ dr.GetString(1);//0 would give you firstname,1 will provide lastname.
}
 
Share this answer
 
v2
Comments
Ubaid ur Rahman IT 11-Jun-13 4:13am    
its working fine, but i dont need this welcome mr in this code

yourlabel.text="Welcome, Mr." + dr.GetString(0)+" "+ dr.GetString(1);

can you please take out welcome mr and display first name and last name from this code.

thanks.
Ubaid ur Rahman IT 11-Jun-13 5:02am    
ya it shows error after removing welcome ... this is my code.

yourlabel.text= + dr.GetString(0)+" "+ dr.GetString(1);

can you please check this ? if its wrong please help me. am fresher.
Thanks7872 11-Jun-13 5:04am    
yourlabel.text= dr.GetString(0)+" "+ dr.GetString(1); + is also highlighted in above updated answer.Try this,it will definitely work.
You can store firstname and lastname (after login) in your session.
This can then be accessed on any page you want.

Remember to clear your session once the user logs out.
 
Share this answer
 
Comments
Ubaid ur Rahman IT 11-Jun-13 4:27am    
can you please hlep me ...

its working fine, but i dont need this welcome mr in this code

yourlabel.text="Welcome, Mr." + dr.GetString(0)+" "+ dr.GetString(1);

can you please take out welcome mr and display first name and last name from this code.

thanks.
Abhinav S 11-Jun-13 4:34am    
I really thing you should try this own your own. Hint - use the string operation subString.
You could infact also use Replace.

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