Skip to content

Object reference not set to an instance of an object.

AbhiPriya M V

Asked Mar 10, 2013, 11:01 PM EDTSolved
Share
LinkedInX

 getting this error                                                            Object reference not set to an instance of an while updating an record in gridview in c#.net..
can anyone help me!!!!

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Vishal Gilbile
    ✓ Accepted answer0
    Hello there,
                   It means that you are trying to dereference a value which is a null reference. Kindly check you GridView1_RowUpdating event where you are finding controls from within the EditItemTemplate and performing a type cast to read the values from those controls.

    The exception stack trace may help you find the problem on which line you are getting the error.



    With Regards,
    Vishal Gilbile.
    0
  • 0

    solved that one now am getting this one..
     Connection property has not been initialized.
    and this my code::
    CSS
    Line 104: Line 105:      SqlCommand cmd = new SqlCommand("update Employee_Details set NAME='" + NAME + "',ADDRESS='" + ADDRESS + "', designation='" + DESIGNATION + "' where ID=" + ID); Line 106:      int result = cmd.ExecuteNonQuery(); Line 107:      con.Close(); Line 108:      if (result == 1)

    0
  • Vishal Gilbile
    0
    The Error is only stating you what is the cause. It saying that you might have not initialized your connectionstring property of your Connection object.

    Eg.

    SqlConnection con=new SqlConnection();

    Over here I created an instance of my SqlConnection class but not initialized the ConnectionString Property of the SqlConnection Class.
    There are 2 ways to do it.

    Way 1:

            SqlConnection con=new SqlConnection("Specify your connection string over here");

    Way 2:

    SqlConnection con=new SqlConnection();
    con.ConnectionString="Specify your Connection string over here";

    Hope that solves your problem.

    With Regards,
    Vishal Gilbile.
    0