Getting this error **System.NullReferenceException: 'Object reference not set to an instance of an object.'** : <p>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.</p>

<p>I have put the breakpoints and inspected the code it shows the values when I hover but also it is throwing this error</p>

<p>This is the place where I get the values from the textboxes and when I hover on the <code>enttity.lender_name</code>(same for all the textboxes) it shows the value in textbox correctly  </p>

<pre><code>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;
        }
    }
</code></pre>

<p>The error is thrown in this line  <code>int update = bal.lenderupdate(enttity, Convert.ToInt32(ViewState["lender_id"].ToString()));</code> and goes to <code>throw ex</code> saying the error <strong>System.NullReferenceException: 'Object reference not set to an instance of an object.'</strong></p>

<p>This my code where it goes to Stored procedure </p>

<pre><code>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;
        }
    }
</code></pre>

<p>The values are coming here to but it is throwing the error </p>

<p>data should go to database and update the details of particular lender</p>
