You are trying to access the reader value on a closed object. i.e
Quote:
if (dr["breast_feeding"].ToString().Equals("Yes"))
is called after the prev connection is closed. what you can do here is copy this value into a local variable and use that here instead of using the dataReader.
bool breastFeeding = false;
if (dr.Read())
{
cbPlaceoforder.SelectedValue = dr["antenatal_care_id"].ToString();
txtAgeofantenatalmother.Text = dr["age"].ToString();
if (dr["regular_anc"].ToString().Equals("Yes"))
{
rbtnRegularancyes.Select();
}
else
{
rbtnRegularancno.Select();
}
breastFeeding = dr["breast_feeding"].ToString().Equals("Yes")?true:false;
}
con.Close();
then use it like below
if (dr1.Read())
{
cbPlaceofanc.SelectedValue = dr1["delivery_place_id"].ToString();
cbTypeofdelivery.SelectedValue = dr1["delivery_type_id"].ToString();
cbMilksupplement.SelectedValue = dr1["milk_suppliment_id"].ToString();
if (breastFeeding)
{
rbtnBreastfeeding1stsixmonthsyes.Select();
}
else
{
rbtnBreastfeeding1stsixmonthsno.Select();
}
}