This code supposed to select charges from table base on the accountno, but it keeps on showing me this error and i don't know why.
Select query error- Object reference not set to an instance of an object.
Error:
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 133: {
Line 134: SqlCommand command = new SqlCommand("SELECT Charges FROM Deposit WHERE Account_No=@Account_No ", con);
Line 135: cmd.Parameters.AddWithValue("@Account_No", this.txtaccountno.Text.Trim());
Line 136: //cmd.Parameters.AddWithValue("@ToDate", this.totxtdate.Text.Trim());
Line 137: con.Open();
code
protected void btnexp_Click(object sender, EventArgs e)
{
string constrr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constrr))
{
SqlCommand command = new SqlCommand("SELECT Charges FROM Deposit WHERE Account_No=@Account_No ", con);
cmd.Parameters.AddWithValue("@Account_No", this.txtaccountno.Text.Trim());
//cmd.Parameters.AddWithValue("@ToDate", this.totxtdate.Text.Trim());
con.Open();
SqlDataReader sdrr = command.ExecuteReader();
if (sdrr.Read())
{
txtchages.Text = sdrr["Charges"].ToString();
}
sdrr.Close();
}