Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Object reference not set to an instance of an object.
 

Object reference not set to an instance of an object.

I get the following error while setting an insert command onto my data adaptor (second line):

Object reference not set to an instance of an object.

adptr_DataAdapter1 = new SqlDataAdapter(str_SQL1, cnn_DataConnection1);
adptr_DataAdapter1.InsertCommand.CommandText = "INSERT INTO tbl_test (str_field1) VALUES('val1')";

Any idea why this is happening?

RKBNAIR  Monday, December 12, 2005 5:45 PM

Create the SqlCommand object first:



  SqlDataAdapter da = new SqlDataAdapter();

  // Create the InsertCommand.   There are many ways to do this...
  da.InsertCommand = cnn_DataConnection1.CreateCommand();

  da.InsertCommand.InsertCommand = "INSERT INTO Customers (CustomerID) VALUES ('val1')";


 

philipsh  Monday, December 12, 2005 6:20 PM

Create the SqlCommand object first:



  SqlDataAdapter da = new SqlDataAdapter();

  // Create the InsertCommand.   There are many ways to do this...
  da.InsertCommand = cnn_DataConnection1.CreateCommand();

  da.InsertCommand.InsertCommand = "INSERT INTO Customers (CustomerID) VALUES ('val1')";


 

philipsh  Monday, December 12, 2005 6:20 PM

You can use google to search for other answers

Custom Search

More Threads

• TableAdapter Datasets and a parameter
• How to connect to secure database
• Importing contact's details in to custom form
• How to set the properties of a remote desktop connection via a windows form
• How to turn on threestate for bound CheckBoxes in DataGridView
• Disable refresh of Control in EditMode upon ItemChanged
• DataTableReader is invalid for current DataTable
• DataGridView accessing a particular cell
• HowTo serialize an xml node as empty tag
• Strange behaviour on a datagridview