SqlRowUpdatedEventArgs Classe
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.
Fournit des données pour l'événement RowUpdated.
public ref class SqlRowUpdatedEventArgs sealed : System::Data::Common::RowUpdatedEventArgs
public sealed class SqlRowUpdatedEventArgs : System.Data.Common.RowUpdatedEventArgs
type SqlRowUpdatedEventArgs = class
inherit RowUpdatedEventArgs
Public NotInheritable Class SqlRowUpdatedEventArgs
Inherits RowUpdatedEventArgs
- Héritage
Exemples
L’exemple suivant montre comment utiliser les événements et RowUpdating les RowUpdated événements.
L’événement RowUpdating retourne cette sortie :
Arguments d’événement : (command=System.Data.SqlClient.SqlCommand commandType=2 status=0)
L’événement RowUpdated retourne cette sortie :
Arguments d’événement : (command=System.Data.SqlClient.SqlCommand commandType=2 recordsAffected=1 row=System.Data.DataRow[37] status=0)
// handler for RowUpdating event
private static void OnRowUpdating(object sender, SqlRowUpdatingEventArgs e)
{
PrintEventArgs(e);
}
// handler for RowUpdated event
private static void OnRowUpdated(object sender, SqlRowUpdatedEventArgs e)
{
PrintEventArgs(e);
}
public static int Main()
{
const string connectionString = "...";
const string queryString = "SELECT * FROM Products";
// create DataAdapter
SqlDataAdapter adapter = new(queryString, connectionString);
SqlCommandBuilder builder = new(adapter);
// Create and fill DataSet (select only first 5 rows)
DataSet dataSet = new();
adapter.Fill(dataSet, 0, 5, "Table");
// Modify DataSet
DataTable table = dataSet.Tables["Table"];
table.Rows[0][1] = "new product";
// add handlers
adapter.RowUpdating += new SqlRowUpdatingEventHandler(OnRowUpdating);
adapter.RowUpdated += new SqlRowUpdatedEventHandler(OnRowUpdated);
// update, this operation fires two events
// (RowUpdating/RowUpdated) per changed row
adapter.Update(dataSet, "Table");
// remove handlers
adapter.RowUpdating -= new SqlRowUpdatingEventHandler(OnRowUpdating);
adapter.RowUpdated -= new SqlRowUpdatedEventHandler(OnRowUpdated);
return 0;
}
private static void PrintEventArgs(SqlRowUpdatingEventArgs args)
{
Console.WriteLine("OnRowUpdating");
Console.WriteLine(" event args: (" +
" command=" + args.Command +
" commandType=" + args.StatementType +
" status=" + args.Status + ")");
}
private static void PrintEventArgs(SqlRowUpdatedEventArgs args)
{
Console.WriteLine("OnRowUpdated");
Console.WriteLine(" event args: (" +
" command=" + args.Command +
" commandType=" + args.StatementType +
" recordsAffected=" + args.RecordsAffected +
" status=" + args.Status + ")");
}
' handler for RowUpdating event
Private Shared Sub OnRowUpdating(sender As Object, e As SqlRowUpdatingEventArgs)
PrintEventArgs(e)
End Sub
' handler for RowUpdated event
Private Shared Sub OnRowUpdated(sender As Object, e As SqlRowUpdatedEventArgs)
PrintEventArgs(e)
End Sub
Public Overloads Shared Function Main(args() As String) As Integer
Const connectionString As String = "..."
Const queryString As String = "SELECT * FROM Products"
' create DataAdapter
Dim adapter As New SqlDataAdapter(queryString, connectionString)
Dim builder As New SqlCommandBuilder(adapter)
' Create and fill DataSet (select only first 5 rows)
Dim dataSet As New DataSet()
adapter.Fill(dataSet, 0, 5, "Table")
' Modify DataSet
Dim table As DataTable = dataSet.Tables("Table")
table.Rows(0)(1) = "new product"
' add handlers
AddHandler adapter.RowUpdating, AddressOf OnRowUpdating
AddHandler adapter.RowUpdated, AddressOf OnRowUpdated
' update, this operation fires two events
'(RowUpdating/RowUpdated) per changed row
adapter.Update(dataSet, "Table")
' remove handlers
RemoveHandler adapter.RowUpdating, AddressOf OnRowUpdating
RemoveHandler adapter.RowUpdated, AddressOf OnRowUpdated
Return 0
End Function
Private Overloads Shared Sub PrintEventArgs(args As SqlRowUpdatingEventArgs)
Console.WriteLine("OnRowUpdating")
Console.WriteLine(" event args: (" & " command=" & args.Command.CommandText &
" commandType=" & args.StatementType & " status=" & args.Status & ")")
End Sub
Private Overloads Shared Sub PrintEventArgs(args As SqlRowUpdatedEventArgs)
Console.WriteLine("OnRowUpdated")
Console.WriteLine(" event args: (" & " command=" & args.Command.CommandText &
" commandType=" & args.StatementType & " recordsAffected=" &
args.RecordsAffected & " status=" & args.Status & ")")
End Sub
End Class
Remarques
L’événement RowUpdated est déclenché lorsqu’une Update ligne est terminée.
Lors de l’utilisation Update, il existe deux événements qui se produisent pour chaque ligne de données mise à jour. L’ordre d’exécution est le suivant :
Les valeurs de l'DataRow sont déplacées vers les valeurs de paramètre.
L'événement OnRowUpdating est déclenché.
La commande s’exécute.
Si la commande est définie
FirstReturnedRecordsur , et que le premier résultat retourné est placé dans le DataRow.S’il existe des paramètres de sortie, ils sont placés dans le DataRow.
L'événement OnRowUpdated est déclenché.
AcceptChanges est appelé.
Constructeurs
| Nom | Description |
|---|---|
| SqlRowUpdatedEventArgs(DataRow, IDbCommand, StatementType, DataTableMapping) |
Initialise une nouvelle instance de la classe SqlRowUpdatedEventArgs. |
Propriétés
| Nom | Description |
|---|---|
| Command |
Obtient ou définit l’exécution SqlCommand lorsqu’elle Update(DataSet) est appelée. |
| Errors |
Obtient toutes les erreurs générées par le fournisseur de données .NET lorsque le Command a été exécuté. (Hérité de RowUpdatedEventArgs) |
| RecordsAffected |
Obtient le nombre de lignes modifiées, insérées ou supprimées par l’exécution de l’instruction SQL. (Hérité de RowUpdatedEventArgs) |
| Row |
Obtient l’envoi DataRow par le biais d’un Update(DataSet). (Hérité de RowUpdatedEventArgs) |
| RowCount |
Obtient le nombre de lignes traitées dans un lot d’enregistrements mis à jour. (Hérité de RowUpdatedEventArgs) |
| StatementType |
Obtient le type d’instruction SQL exécuté. (Hérité de RowUpdatedEventArgs) |
| Status |
Obtient la UpdateStatusCommand propriété. (Hérité de RowUpdatedEventArgs) |
| TableMapping |
Obtient l’envoi DataTableMapping par le biais d’un Update(DataSet). (Hérité de RowUpdatedEventArgs) |
Méthodes
| Nom | Description |
|---|---|
| CopyToRows(DataRow[], Int32) |
Copie les références aux lignes modifiées dans le tableau fourni. (Hérité de RowUpdatedEventArgs) |
| CopyToRows(DataRow[]) |
Copie les références aux lignes modifiées dans le tableau fourni. (Hérité de RowUpdatedEventArgs) |
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |