如何使用标签显示名字和姓氏 [英] how to display firstname and last name using label

查看:117
本文介绍了如何使用标签显示名字和姓氏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我正在使用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.

推荐答案

我认为你是初学者。建议你最简单所以你可以知道如何处理这类东西。



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.

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.
}


您可以在会话中存储名字和姓氏(登录后)。

然后可以在任何您想要的页面上访问它。 br />


一旦用户退出,请记得清除会话。
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.


这篇关于如何使用标签显示名字和姓氏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆