OleDbDataAdapter.UpdateCommand Propriété

Définition

Obtient ou définit une instruction SQL ou une procédure stockée utilisée pour mettre à jour les enregistrements dans la source de données.

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; }
public System.Data.OleDb.OleDbCommand? UpdateCommand { get; set; }
[System.Data.DataSysDescription("DbDataAdapter_UpdateCommand")]
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

Valeur de propriété

OleDbCommand utilisé lors de Update(DataSet) pour mettre à jour les enregistrements dans la source de données qui correspondent à des lignes modifiées dans le DataSet.

Attributs

Exemples

L’exemple suivant crée un OleDbDataAdapter et définit les SelectCommand propriétés et UpdateCommand . Il suppose que vous avez déjà créé un OleDbConnection objet.

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

Remarques

Pendant Update, si cette propriété n’est pas définie et que des informations sur la clé primaire sont présentes dans , DataSetle UpdateCommand peut être généré automatiquement si vous définissez la SelectCommand propriété et utilisez .OleDbCommandBuilder Ensuite, toutes les commandes supplémentaires que vous ne définissez pas sont générées par .OleDbCommandBuilder Cette logique de génération nécessite que les informations de colonne clés soient présentes dans .DataSet Pour plus d’informations, consultez Génération de commandes avec CommandBuilders.

Quand UpdateCommand est affecté à un précédemment créé OleDbCommand, le n’est OleDbCommand pas cloné. conserve UpdateCommand une référence à l’objet créé précédemment OleDbCommand .

Notes

Si l’exécution de cette commande retourne des lignes, ces lignes peuvent être fusionnées avec le en fonction de la DataSet façon dont vous définissez la UpdatedRowSource propriété de l’objet OleDbCommand .

S’applique à