Share via


OleDbDataAdapter.InsertCommand Propiedad

Definición

Obtiene o establece una instrucción SQL o procedimiento almacenado utilizado para insertar nuevos registros en el origen de datos.

public:
 property System::Data::OleDb::OleDbCommand ^ InsertCommand { System::Data::OleDb::OleDbCommand ^ get(); void set(System::Data::OleDb::OleDbCommand ^ value); };
public System.Data.OleDb.OleDbCommand? InsertCommand { get; set; }
[System.Data.DataSysDescription("DbDataAdapter_InsertCommand")]
public System.Data.OleDb.OleDbCommand InsertCommand { get; set; }
public System.Data.OleDb.OleDbCommand InsertCommand { get; set; }
member this.InsertCommand : System.Data.OleDb.OleDbCommand with get, set
[<System.Data.DataSysDescription("DbDataAdapter_InsertCommand")>]
member this.InsertCommand : System.Data.OleDb.OleDbCommand with get, set
Public Property InsertCommand As OleDbCommand

Valor de propiedad

OleDbCommand utilizado durante Update(DataSet) para insertar registros en el origen de datos que se corresponde con las filas nuevas de DataSet.

Atributos

Ejemplos

En el ejemplo siguiente se crea y OleDbDataAdapter se establecen las SelectCommand propiedades y InsertCommand . Se supone que ya ha creado un OleDbConnection objeto .

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;
}
Public Shared Function CreateCustomerAdapter( _
    connection As OleDbConnection) As OleDbDataAdapter 
  
    Dim adapter As New OleDbDataAdapter()
    Dim command As OleDbCommand

    ' 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
End Function

Comentarios

Durante Update, si esta propiedad no está establecida y la información de clave principal está presente en DataSet, InsertCommand se puede generar automáticamente si establece la SelectCommand propiedad y usa .OleDbCommandBuilder A continuación, los comandos adicionales que no establezca se generan mediante .OleDbCommandBuilder Esta lógica de generación requiere que la información de columna de clave esté presente en .DataSet Para obtener más información, vea Generar comandos con objetos CommandBuilder.

Cuando InsertCommand se asigna a un objeto creado OleDbCommandanteriormente, OleDbCommand no se clona. InsertCommand mantiene una referencia al objeto creado OleDbCommand anteriormente.

Nota

Si la ejecución de este comando devuelve filas, estas filas se pueden agregar a DataSet según cómo establezca la UpdatedRowSource propiedad del OleDbCommand objeto.

Se aplica a

Consulte también