Object reference not set to an instance of an object.
getting this error Object reference not set to an instance of an while updating an record in gridview in c#.net..
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Vishal GilbileRank #269 · 9.4K pointsPosted Mar 10, 2013, 11:10 PM EDT
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.
AbhiPriya M V45 pointsPosted Mar 10, 2013, 11:50 PM EDT
solved that one now am getting this one..
Connection property has not been initialized.
and this my code::
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)Vishal GilbileRank #269 · 9.4K pointsPosted Mar 11, 2013, 1:10 AM EDT
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.