如何从查询结果中获取值到标签?
我有两个标签,一个是labelName,另一个是labelDepartment
因此,当我运行查询时,如何从查询结果中获取值并使用 c# 将其分配给标签?
这是我的 Sql 命令:
"SELECT tbl_staff.staffName,tbl_department.department
FROM tbl_staff,tbl_logs,tbl_department
WHERE tbl_staff.userID = tbl_logs." + listStaff.SelectedValue + " and tbl_staff.idDepartment = tbl_department.idDepartment;"
这是 C# 中的当前代码
//Open SQL connection
SqlConnection openCon = new SqlConnection(connString);
openCon.Open();
string SQL = string.Format("SELECT tbl_staff.staffName,tbl_department.department FROM tbl_staff,tbl_logs,tbl_department WHERE tbl_staff.userID = tbl_logs.userID and tbl_staff.idDepartment = tbl_department.idDepartment" + listStaff.SelectedValue + ";");
SqlCommand command = new SqlCommand(SQL);
SqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
labelName.Text = reader["tbl_staff.staffName"];
labelDepartment.Text = reader["tbl_department.department"];
}
注意:我们的记录将只返回一行.. MS SQL 和 C#.. 感谢您的帮助...;)