MySqlDataAdapter.InsertCommand Property

MySQL Connector/Net

MySqlDataAdapterInsertCommand Property
Gets or sets a SQL statement or stored procedure used to insert records into the data set.

Namespace: MySql.Data.MySqlClient
Assembly: MySql.Data (in MySql.Data.dll) Version: 6.9.9
Syntax
public MySqlCommand InsertCommand { get; set; }
Public Property InsertCommand As MySqlCommand
	Get
	Set
public:
property MySqlCommand^ InsertCommand {
	MySqlCommand^ get ();
	void set (MySqlCommand^ value);
}
member InsertCommand : MySqlCommand with get, set

Property Value

Type: MySqlCommand
A MySqlCommand used during Update(DataSet) to insert records into the database that correspond to new rows in the DataSet.
Remarks

During Update(DataSet), 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 MySqlCommandBuilder. Then, any additional commands that you do not set are generated by the MySqlCommandBuilder. This generation logic requires key column information to be present in the DataSet.

When InsertCommand is assigned to a previously created MySqlCommand, the MySqlCommand is not cloned. The InsertCommand maintains a reference to the previously created MySqlCommand object.

Note 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 MySqlCommand object.
Examples
The following example creates a MySqlDataAdapter and sets the SelectCommand and InsertCommand properties. It assumes you have already created a MySqlConnection object.
public static MySqlDataAdapter CreateCustomerAdapter(MySqlConnection conn)
{
MySqlDataAdapter da = new MySqlDataAdapter();
MySqlCommand cmd;
MySqlParameter parm;

// Create the SelectCommand.
cmd = new MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn);

cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15);
cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15);

da.SelectCommand = cmd;

// Create the InsertCommand.
cmd = new MySqlCommand("INSERT INTO mytable (id,name) VALUES (@id,@name)", conn);
cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15, "id" );
cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15, "name" );

da.InsertCommand = cmd;

return da;
}
Public Shared Function CreateCustomerAdapter(conn As MySqlConnection) As MySqlDataAdapter

Dim da As MySqlDataAdapter = New MySqlDataAdapter()
Dim cmd As MySqlCommand
Dim parm As MySqlParameter

' Create the SelectCommand.
cmd = New MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn)

cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15)
cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15)

da.SelectCommand = cmd

' Create the InsertCommand.
cmd = New MySqlCommand("INSERT INTO mytable (id,name) VALUES (@id, @name)", conn)

cmd.Parameters.Add( "@id", MySqlDbType.VarChar, 15, "id" )
cmd.Parameters.Add( "@name", MySqlDbType.VarChar, 15, "name" )
da.InsertCommand = cmd

Return da
End Function

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also