ASP.NET SQL查询所有结果打印标签 [英] ASP.NET SQL Query All Result Print Label
问题描述
我将查询结果打印到网格视图中,但是我想打印成一个带有名字的标签,如名字++姓氏,请帮忙。
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(选择名字,来自FriendsAccount的姓氏,con);
sda.Fill( dt);
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Visible = true;
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;
推荐答案
如下所示进行连接
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
这篇关于ASP.NET SQL查询所有结果打印标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!