我试图让两个警察当句柄列等于下拉列表的值从名为PoliceAccount和fullname ,然后将值放入标签中并显示它。通过使用下面提供的代码,我不断得到policyid和fullname的最后一行数据的结果。但是,我的表包含 2 个警察帐户,其列句柄等于下拉列表的值。帮帮我吧。谢谢!
conn.Open();
sql = "Select policeid, fullname From PoliceAccount Where handle = '"+ ddlReportDateTime.SelectedValue +"'";
using (var cmd2 = new SqlCommand(sql, conn))
{
SqlDataReader dr;
dr = cmd2.ExecuteReader();
while (dr.Read())
{
String policeid = dr.GetString(0);
String fullname = dr.GetString(1);
String result = policeid + " " + fullname;
lblAssignTo.Text = result;
}
}
conn.Close();