简体   繁体   English

登录时显示全名而不是用户名

[英]Displaying Fullname On Login Rather Than Username

I've created a login window for my C# application but users logon with the username which is connected to my SQL Database but what I want is a Label which says "Welcome [Full Name]" at this moment I have a string which gets the userID from the textbox so it puts whatever the user has signed on with but I don't want the username I want the Full name which is in the table in the database. I've created a login window for my C# application but users logon with the username which is connected to my SQL Database but what I want is a Label which says "Welcome [Full Name]" at this moment I have a string which gets the来自文本框中的用户 ID,因此它会放置用户已登录的任何内容,但我不想要用户名,我想要数据库表中的全名。

How would I go about adding an SQL Command onto this "Welcome" label on the main window when the user logs on, it would need a "SELECT FULLNAME FROM USERS WHERE USERID='" + usernametxt.Text but how would I write the label to be connected to this SQL command result? How would I go about adding an SQL Command onto this "Welcome" label on the main window when the user logs on, it would need a "SELECT FULLNAME FROM USERS WHERE USERID='" + usernametxt.Text but how would I write the label要连接到这个 SQL 命令结果?

These are the steps to take:这些是要采取的步骤:

It is most advisable to use parameters in your select statements for your login logic like others have commented to prevent sql injection.最好在您的 select 语句中为您的登录逻辑使用参数,就像其他人评论的那样,以防止 sql 注入。 check www.w3schools.com under their sql tutorial and click to sqlinjection to understand why, here is an example though;在他们的 sql 教程下查看 www.w3schools.com 并单击 sqlinjection 以了解原因,但这里是一个示例;

string txtUserId = usernametxt.Text;
string txtPassword= passwordtxt.Text;
sql = "SELECT * FROM USERS WHERE UserId= @User and 
Password= @Password";
command = new SqlCommand(sql);
command.Parameters.AddWithValue("@User",txtUserID);
command.Parameters.AddWithValue("@Password",txtPassword);
command.ExecuteReader();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM