SqlRowUpdatedEventArgs Classe

Definizione

Fornisce i dati per l'evento 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
Ereditarietà
SqlRowUpdatedEventArgs

Esempio

Nell'esempio seguente viene illustrato come usare gli RowUpdating eventi e RowUpdated .

L'evento RowUpdating restituisce questo output:

Argomenti evento: (command=System.Data.SqlClient.SqlCommand commandType=2 status=0)

L'evento RowUpdated restituisce questo output:

Argomenti evento: (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

Commenti

L'evento RowUpdated viene generato quando viene completato un Update oggetto a una riga.

Quando si usa Update, sono presenti due eventi che si verificano per ogni riga di dati aggiornata. L'ordine di esecuzione è il seguente:

  1. I valori in DataRow vengono spostati nei valori dei parametri.

  2. Viene generato l'evento OnRowUpdating.

  3. Il comando viene eseguito.

  4. Se il comando è impostato su FirstReturnedRecorde il primo risultato restituito viene inserito in DataRow.

  5. Se sono presenti parametri di output, vengono inseriti in DataRow.

  6. Viene generato l'evento OnRowUpdated.

  7. Si chiama AcceptChanges.

Costruttori

Nome Descrizione
SqlRowUpdatedEventArgs(DataRow, IDbCommand, StatementType, DataTableMapping)

Inizializza una nuova istanza della classe SqlRowUpdatedEventArgs.

Proprietà

Nome Descrizione
Command

Ottiene o imposta l'oggetto SqlCommand eseguito quando Update(DataSet) viene chiamato.

Errors

Ottiene eventuali errori generati dal provider di dati .NET quando è stato eseguito il Command.

(Ereditato da RowUpdatedEventArgs)
RecordsAffected

Ottiene il numero di righe modificate, inserite o eliminate dall'esecuzione dell'istruzione SQL.

(Ereditato da RowUpdatedEventArgs)
Row

Ottiene l'oggetto DataRow inviato tramite un oggetto Update(DataSet).

(Ereditato da RowUpdatedEventArgs)
RowCount

Ottiene il numero di righe elaborate in un batch di record aggiornati.

(Ereditato da RowUpdatedEventArgs)
StatementType

Ottiene il tipo di istruzione SQL eseguita.

(Ereditato da RowUpdatedEventArgs)
Status

Ottiene l'oggetto UpdateStatus della Command proprietà .

(Ereditato da RowUpdatedEventArgs)
TableMapping

Ottiene l'oggetto DataTableMapping inviato tramite un oggetto Update(DataSet).

(Ereditato da RowUpdatedEventArgs)

Metodi

Nome Descrizione
CopyToRows(DataRow[], Int32)

Copia i riferimenti alle righe modificate nella matrice specificata.

(Ereditato da RowUpdatedEventArgs)
CopyToRows(DataRow[])

Copia i riferimenti alle righe modificate nella matrice specificata.

(Ereditato da RowUpdatedEventArgs)
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a

Vedi anche