Export (0) Print
Expand All

DbDataAdapter.InsertCommand Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets a command used to insert new records into the data source.

Namespace: System.Data.Common
Assembly: System.Data (in system.data.dll)

public DbCommand InsertCommand { get; set; 
/** @property */
public DbCommand get_InsertCommand ()

/** @property */
public void set_InsertCommand (DbCommand value)

public function get InsertCommand () : DbCommand

public function set InsertCommand (value : DbCommand)

Property Value

A IDbCommand used during Update to insert records in the data source for new rows in the data set.

During Update, if this property is not set and primary key information is present in the DataSet, the InsertCommand will be automatically generated.

The following example creates the derived class OleDbDataAdapter and sets some of its properties.

public static OleDbDataAdapter CreateCustomerAdapter(
    OleDbConnection connection)
{
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    OleDbCommand command;

    // Create the SelectCommand.
    command = new OleDbCommand("SELECT CustomerID FROM Customers " +
        "WHERE Country = ? AND City = ?", connection);

    command.Parameters.Add("Country", OleDbType.VarChar, 15);
    command.Parameters.Add("City", OleDbType.VarChar, 15);

    adapter.SelectCommand = command;

    // Create the InsertCommand.
    command = new OleDbCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)", connection);

    command.Parameters.Add(
        "CustomerID", OleDbType.Char, 5, "CustomerID");
    command.Parameters.Add(
        "CompanyName", OleDbType.VarChar, 40, "CompanyName");

    adapter.InsertCommand = command;
    return adapter;


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft