问题描述
嗨朋友们,
我正在使用asp.net c#,Sqlserver 2005.
i want使用标签显示用户的名字和姓氏
----------
我有登录页面,在这里我有用户名和密码登录,
欢迎页面我有标签显示登录用户名。
例如我的登录用户名是rahman
在我的数据库中我的名字是穆罕默德,姓氏是拉赫曼
现在登录后我想在欢迎页面显示为
欢迎先生穆罕默德拉赫曼(名字和姓氏)
请帮助谢谢。
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.
推荐答案
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.
}
这篇关于如何使用标签显示名字和姓氏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!