Object reference not set to an instance of an object.
i have a 5 textboxes in asp.net webpad
i enter the consumerno in the first textbox, and click on the search so that it takes the record of other 4 cells of that particular record and show it in the given 4 textboxes. here is the code:
protected void Button2_Click(object sender, EventArgs e)
{
cmd = new SqlCommand("select * from Arrear where ConsumerNo='" + ConsumerNo.Text + "'", con);
ad.SelectCommand = cmd;
con.Open();
ad.Fill(ds);
ConsumerNo.Text = ds.Tables[0].Rows[0].ItemArray[1].ToString();
WaterCharges.Text = ds.Tables[0].Rows[0].ItemArray[2].ToString();
ConservancyCharges.Text = ds.Tables[0].Rows[0].ItemArray[3].ToString();
SaverageCharges.Text = ds.Tables[0].Rows[0].ItemArray[4].ToString();
arear.Text = ds.Tables[0].Rows[0].ItemArray[5].ToString();
}
but i got the following error:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Line 80: cmd = new SqlCommand("select * from Arrear where ConsumerNo='" + ConsumerNo.Text + "'", con);
Line 81: ad.SelectCommand = cmd;
please help me.