I have a page which updates the details of lender in the database but when I click the update button it is throwing this error.
I have put the breakpoints and inspected the code it shows the values when I hover but also it is throwing this error
This is the place where I get the values from the textboxes and when I hover on the enttity.lender_name
(same for all the textboxes) it shows the value in textbox correctly
protected void btn_update_Click(object sender, EventArgs e)
{
try
{
enttity.lender_name = lender_name.Text;
enttity.lender_code = lender_code.Text;
enttity.manager_name = manager_name.Text;
enttity.manager_number = manager_number.Text;
enttity.lc_number = lc_number.Text;
enttity.manager_email = manager_email.Text;
enttity.lc_email = lc_email.Text;
enttity.contact_name = contact_name.Text;
enttity.designation = designation.Text;
enttity.branch_name = branch_name.Text;
enttity.branch_add = branch_add.Text;
enttity.branch_add2 = branch_add2.Text;
enttity.branch_city = branch_city.Text;
enttity.branch_state = branch_state.Text;
enttity.branch_zip = branch_zip.Text;
enttity.branch_country = branch_country.Text;
int update = bal.lenderupdate(enttity, Convert.ToInt32(ViewState["lender_id"].ToString()));
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert(' Successfully updated!');window.location.href = 'Lender_registration.aspx'", true);
}
catch (Exception ex)
{
throw ex;
}
}
The error is thrown in this line int update = bal.lenderupdate(enttity, Convert.ToInt32(ViewState["lender_id"].ToString()));
and goes to throw ex
saying the error System.NullReferenceException: 'Object reference not set to an instance of an object.'
This my code where it goes to Stored procedure
public int lenderupdate(lender_entity enttity, int lender_id)
{
try
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@lender_id ", lender_id);
cmd.Parameters.AddWithValue("@lender_name ", enttity.lender_name);
cmd.Parameters.AddWithValue("@lender_code", enttity.lender_code);
cmd.Parameters.AddWithValue("@manager_name", enttity.manager_name);
cmd.Parameters.AddWithValue("@manager_number ", enttity.manager_number);
cmd.Parameters.AddWithValue("@lc_number", enttity.lc_number);
cmd.Parameters.AddWithValue("@manager_email", enttity.manager_email);
cmd.Parameters.AddWithValue("@lc_email ", enttity.lc_email);
cmd.Parameters.AddWithValue("@contact_name", enttity.contact_name);
cmd.Parameters.AddWithValue("@designation", enttity.designation);
cmd.Parameters.AddWithValue("@branch_name ", enttity.branch_name);
cmd.Parameters.AddWithValue("@branch_add", enttity.branch_add);
cmd.Parameters.AddWithValue("@branch_add2", enttity.branch_add2);
cmd.Parameters.AddWithValue("@branch_city", enttity.branch_city);
cmd.Parameters.AddWithValue("@branch_state", enttity.branch_state);
cmd.Parameters.AddWithValue("@branch_zip", enttity.branch_zip);
cmd.Parameters.AddWithValue("@branch_country", enttity.branch_country);
int updatelender = dbmngr.ExecuteNonQuery(cmd, CommandType.StoredProcedure, "updatelenders");
return updatelender;
}
catch (Exception ex)
{
throw ex;
}
}
The values are coming here to but it is throwing the error
data should go to database and update the details of particular lender