我执行了一个查询,它给了我一行3列。当我尝试使用reader.Read()
读取它时,它不会读取任何行。虽然reader.FieldCount =3
表示reader.Read
,但没有行..
protected void btnSearch_Click(object sender, EventArgs e)
{
string connectionString = GlobalVariables.databasePath;
SqlConnection sqlCon = new SqlConnection(connectionString);
if (txtSearch.Text != null)
{
string query = "select fac.fac_name,dp.dp_name,br.br_name "
+ "from STUDENT s,DIVISON dv,BRANCH br,DEPT dp,FACULTY fac,CLASS cls,DEGREE dg "
+ "where dg.dg_id=cls.dg_id and cls.cls_id=s.cls_id and fac.fac_id=dp.fac_id and dp.dp_id=br.dp_id and br.br_id=dv.br_id and s.dv_id=dv.dv_id and s.prn_no=" + txtSearch.Text;
sqlCon.Open();
SqlCommand cmd = new SqlCommand(query, sqlCon);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
string facultyName = reader.GetValue(0).ToString();
string deptName = reader.GetValue(1).ToString();
string branchName = reader.GetValue(2).ToString();
//some other code..
}
else
{
lblMessage.Text = "No Row found..";
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}