0

i have executed a query which gives me 1 row with 3 column. nut when i tried to read it using reader.Read(), it doesn't read any row. Though reader.FieldCount =3, it says reader.Read says , no row..

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;
        }
    }
jhmt
  • 1,401
  • 1
  • 11
  • 15
Roy
  • 1

0 Answers0