Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I print query result into the Grid View, but I want to print into a label with a loop like First Name + " " + Last Name, please help.

DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter("select First Name, Last Name from FriendsAccount", con);
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Visible = true;
Posted

1 solution

Do Concatenation like below
SQL
select First Name + ' ' + Last Name AS Full_Name from FriendsAccount

Always put the columns(which has space in name) inside square brackets. Better avoid spaces in column names.
SQL
select [First Name] + ' ' + [Last Name] AS Full_Name from FriendsAccount
 
Share this answer
 
v2
Comments
abdulsafran 12-Dec-13 7:58am    
Thank you very much thatraja, I have one more question, how can I preview particular person profile image?
thatraja 12-Dec-13 8:07am    
Did you search Google for that? You need to use Image control & assign the image to Image control's ImageUrl property. <ahref="http: www.w3schools.com="" aspnet="" control_image.asp"="">Image control
abdulsafran 12-Dec-13 8:09am    
Can you please send me one example link?
thatraja 12-Dec-13 8:10am    
example for what?
abdulsafran 12-Dec-13 8:12am    
Please see following link and provide your answer http://www.codeproject.com/Questions/695794/ASP-NET-SQL-Query-Result-Print-Details-Name-and-Vi

Thanks a lot.

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