![](/img/trans.png)
[英]How I get the username after login in the dashboard in c# windows application form
[英]After Login Username gets displayed on dashboard in C#
在 C# 应用程序中,我想在仪表板表单中设置/显示用户名(登录),那么我该怎么做。 提前致谢。 以下是我的代码。
con.dataGet("Select * from [User] Where UserName = '"+txtUserName.Text+"' AND Password = '"+txtPassword.Text+"'");
DataTable dt = new DataTable();
con.sda.Fill(dt);
if (dt.Rows.Count > 0)
{
this.Hide();
frmMain frm = new frmMain();
frm.Show();
}
else
{
MessageBox.Show("Invalid Username And Password..!", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
请帮我。 问候, 达拉姆拉吉
首先,也是最重要的一点,永远不要使用串联的 SQL 查询,因为您很容易受到 SQL 注入的攻击。 使用参数将值传递到 SQL 命令中。 如何使用它们的示例: SqlCommand 参数。
其次,要获取您需要的数据,您只需简单地使用dt
变量填充数据库中的信息。
if (dt.Rows.Count > 0)
{
//getting the value from the DataTable
var userName = dt.Rows[0]["UserName_Column"];
//at this point you have the user name
//also a good idea is to store the user id, if available
this.Hide();
frmMain frm = new frmMain();
frm.Show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.