Compartir por


OleDbDataAdapter.UpdateCommand Propiedad

Definición

Obtiene o establece una instrucción SQL o un procedimiento almacenado que se usa para actualizar los registros del origen de datos.

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

Valor de propiedad

que OleDbCommand se usa durante Update(DataSet) para actualizar los registros del origen de datos que corresponden a las filas modificadas de DataSet.

Atributos

Ejemplos

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

private static OleDbDataAdapter CreateCustomerAdapter(
    OleDbConnection connection)
{
    OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
    OleDbCommand command;
    OleDbParameter parameter;

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

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

    dataAdapter.SelectCommand = command;

    // Create the UpdateCommand.
    command = new OleDbCommand(
        "UPDATE dbo.Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?", connection);

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

    parameter = command.Parameters.Add(
        "oldCustomerID", OleDbType.Char, 5, "CustomerID");
    parameter.SourceVersion = DataRowVersion.Original;

    dataAdapter.UpdateCommand = command;

    return dataAdapter;
}
Private Function CreateCustomerAdapter( _
    ByVal connection As OleDbConnection) As OleDbDataAdapter

    Dim dataAdapter As New OleDbDataAdapter()
    Dim command As OleDbCommand
    Dim parameter As OleDbParameter

    ' Create the SelectCommand.
    command = New OleDbCommand("SELECT * FROM dbo.Customers " & _
        "WHERE Country = ? AND City = ?", connection)

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

    dataAdapter.SelectCommand = command

    ' Create the UpdateCommand.
    command = New OleDbCommand("UPDATE dbo.Customers " & _
        "SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?", connection)

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

    parameter = command.Parameters.Add( _
        "oldCustomerID", OleDbType.Char, 5, "CustomerID")
    parameter.SourceVersion = DataRowVersion.Original

    dataAdapter.UpdateCommand = command

    Return dataAdapter
End Function

Comentarios

Durante Update, si esta propiedad no está establecida y la información de clave principal está presente en DataSet, se UpdateCommand 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 CommandBuilders.

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

Nota:

Si la ejecución de este comando devuelve filas, estas filas se pueden combinar con en DataSet función de cómo establezca la UpdatedRowSource propiedad del OleDbCommand objeto.

Se aplica a