Wednesday 26 September 2012

Object reference not set to an instance of an object

Here I Need To Update The Record. When I click On Update Button I Got An Exception:
This Is The Exception I Got. i.e., "NullReferenceException was unhandled,Object reference not set to an instance of an object" as shown Below:
 I Got The Exception Because At The Instantiation Of  "OleDbDataAdapter da" ,I Had Assigned "Null" To the OleDbDataAdapter da;i.e.,"OleDbDataAdapeter da=Null". Here We Have Not To Set The Instance Of Object Reference To Null,If We Set It To Null Then "NullReference was unhandled" Exception Will Occur..So To Overcome This We Have TO Remove THe Assigning Null To OleDbDataAdapter Object i.e.,OleDbDataAdapter da;

Actually We Can Assign "Null" To The "OleDbDataAdapter" At The Time Of Data Insertion To The DataBase.Becuase The New Data Is Inserting In To The Database Which Its Initial Value Would Be "Null".
But For Updating The Data Of The Database, It Is Not Null Value, We Are Updating/Modifying The Existing Data..So We Should Not Assign Null To The OleDbDataAdapter Which provides the communication between the Dataset and the OleDb Data Sources.




After The Declaration Of OleDbDataAdapter We Have To Create new Object At The Time OF Updation Only. i.e., We Have to Create New Object In "Btn_Update_Click()" Event as Shown In The Below:


 After Removing The Null That Is Assigned To The OleDbDataAdapter.. The Form Runs SuccessFully without Any Exception.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.