System.Data.OleDb Namespace OleDbDataAdapter Class
Sets or retrieves an SQL statement used to insert new records into the data source.
[ VB ]
Public Property InsertCommand As OleDbCommand
[ C# ]
public OleDbCommand InsertCommand {get; set;}
[ C++ ]
public: __property OleDbCommand* get_InsertCommand ( );
public: __property void set_InsertCommand ( OleDbCommand* );
[ C++ ]
public function get InsertCommand ( ) : OleDbCommand;
public function set InsertCommand ( OleDbCommand );
An OleDbCommand used during Update to insert records in the data source that correspond to new rows in the DataSet.
During Update, if this property is not set and primary key information is present in the DataSet, the InsertCommand can be generated automatically if you set the SelectCommand property and use the OleDbCommandBuilder. Then, any additional commands that you do not set are generated by the OleDbCommandBuilder. This generation logic requires key column information to be present in the DataSet. For more information see Automatically Generated Commands.
When InsertCommand is assigned to a previously created OleDbCommand, the OleDbCommand is not cloned. The InsertCommand maintains a reference to the previously created OleDbCommand object.
NOTE: If execution of this command returns rows, these rows may be added to the DataSet depending on how you set the UpdatedRowSource property of the OleDbCommand object.
The following example initializes an OleDbDataAdapter and sets some of its properties.
string myConn = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=gear.mdb";
string query = "SELECT * FROM Products ORDER BY ProductID";
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter ( query, myConn );
myDataAdapter.InsertCommand.CommandText =
"INSERT INTO Products VALUES ( 'Supplies','Cookware','campstove.jpg' ) ";
myDataAdapter.InsertCommand.Connection =
myDataAdapter.SelectCommand.Connection;
Dim myConn As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=gear.mdb"
Dim query As String = "SELECT * FROM Products ORDER BY ProductID"
Dim myDataAdapter As New OleDbDataAdapter ( query, myConn )
myDataAdapter.InsertCommand.CommandText = _
"INSERT INTO Products VALUES ( 'Supplies','Cookware','campstove.jpg' ) "
myDataAdapter.InsertCommand.Connection = _
myDataAdapter.SelectCommand.Connection |
|
C# |
VB |
OleDbDataAdapter Members DeleteCommand SelectCommand UpdateCommand