Partager via


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; }
[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

Valeur de propriété

Utilisé OleDbCommand pendant Update(DataSet) la mise à jour des enregistrements dans la source de données qui correspondent aux lignes modifiées dans le DataSet.

Attributs

Exemples

L’exemple suivant crée un OleDbDataAdapter et définit les propriétés et UpdateCommand les SelectCommand propriétés. Il part du principe 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 les informations de clé primaire sont présentes dans le DataSet, elles UpdateCommand peuvent être générées automatiquement si vous définissez la SelectCommand propriété et utilisez le OleDbCommandBuilder. Ensuite, toutes les commandes supplémentaires que vous ne définissez pas sont générées par le OleDbCommandBuilder. Cette logique de génération nécessite que les informations de colonne clés soient présentes dans le DataSet. Pour plus d’informations, consultez Génération de commandes avec CommandBuilders.

Lorsqu’il UpdateCommand est affecté à un précédemment créé OleDbCommand, il OleDbCommand n’est pas cloné. Conserve UpdateCommand une référence à l’objet créé OleDbCommand précédemment.

Note

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

S’applique à