我创建了 3 个下拉列表,我想按学生姓名、父亲姓名或序列号进行搜索。当我选择学生姓名或父亲姓名并写下姓名时,它会显示数据。但是当我选择“按序列号”搜索时,出现错误:
已经有一个
DataReader
与此命令关联的打开,必须先关闭。
我试图关闭 dataReader 但它不起作用。
protected void btnSearch_Click(object sender, EventArgs e)
{
string QueryStudent = "Select SerialNumber as [Serial No.], Name as [Student Name], FatherName as Father,Phone,Course, AdmissionDate as[Admission date], Status from tblStudents where Name= '" + txtSearch.Text + "'";
string QueryFather = "Select SerialNumber as [Serial No.], Name as [Student Name], FatherName as Father,Phone,Course, AdmissionDate as[Admission date], Status from tblStudents where FatherName= '" + txtSearch.Text + "'";
string QuerySerial = "Select SerialNumber as [Serial No.], Name as [Student Name], FatherName as Father,Phone,Course, AdmissionDate as[Admission date], Status from tblStudents where SerialNumber= '" + txtSearch.Text + "'";
con.Open();
using (var sqlCommand = new SqlCommand(QueryStudent, con))
using (var sqlCommand2 = new SqlCommand(QueryFather, con))
using (var sqlCommand3 = new SqlCommand(QuerySerial, con))
{
SqlDataReader reader = sqlCommand.ExecuteReader();
if (DropDownList.SelectedItem.Value == "By Student Name")
{
if (!reader.HasRows)
{
GrindSearch.Visible = false;
lblmsg.Visible = true;
lblmsg.Text = "No Record found";
}
犯罪嫌疑人X
冉冉说
相关分类