Click here to Skip to main content
14,085,548 members
Rate this:
 
Please Sign up or sign in to vote.
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

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

Solution 1

Do Concatenation like below
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.
select [First Name] + ' ' + [Last Name] AS Full_Name from FriendsAccount
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190518.1 | Last Updated 12 Dec 2013
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

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