【发布时间】:2021-06-19 18:41:06
【问题描述】:
我想在用户成功登录后获取FullName,并将他们的FullName 放入label
string conn = ConfigurationManager.ConnectionStrings["SystemDatabase"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(conn);
sqlconn.Open();
string query = "Select * from UserAccount where Username = '" + txtUsername.Text.Trim() + "' and Password = '" + txtPassword.Text.Trim() + "'";
SqlDataAdapter sda = new SqlDataAdapter(query,sqlconn);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count == 1)
{
FrmPOS frm = new FrmPOS();
frm.Show();
frm.lblCashierName.Text = ?//here i want to display the fullname from the UserAccount table.
this.Hide();
}
我不知道如何从DataTable 获取数据。或者有没有其他方法可以做到?
【问题讨论】:
-
SQL Injection alert - 你应该不将你的 SQL 语句连接在一起 - 使用 参数化查询 来避免 SQL 注入 - 查看Little Bobby Tables
标签: c# sql-server winforms