IDbDataAdapter.UpdateCommand Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit une instruction SQL utilisée pour mettre à jour les enregistrements dans la source de données.
public:
property System::Data::IDbCommand ^ UpdateCommand { System::Data::IDbCommand ^ get(); void set(System::Data::IDbCommand ^ value); };
public System.Data.IDbCommand UpdateCommand { get; set; }
member this.UpdateCommand : System.Data.IDbCommand with get, set
Public Property UpdateCommand As IDbCommand
Valeur de propriété
Utilisé IDbCommand pendant Update(DataSet) la mise à jour des enregistrements dans la source de données pour les lignes modifiées dans le jeu de données.
Exemples
L’exemple suivant crée une instance de la classe héritée OleDbDataAdapter et définit les propriétés et SelectCommand les UpdateCommand 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é d’un fournisseur de données .NET Framework. Ensuite, toutes les commandes supplémentaires que vous ne définissez pas sont générées par CommandBuilder. 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éé IDbCommand, il IDbCommand n’est pas cloné. Conserve UpdateCommand une référence à l’objet créé IDbCommand précédemment.
Note
Si l’exécution de cette commande retourne des lignes, ces lignes sont ajoutées au DataSet.