Leggere in inglese

Condividi tramite


SqlRowUpdatingEventArgs Classe

Definizione

Fornisce i dati per l'evento RowUpdating.

C#
public sealed class SqlRowUpdatingEventArgs : System.Data.Common.RowUpdatingEventArgs
Ereditarietà
SqlRowUpdatingEventArgs

Esempio

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

L'evento RowUpdating restituisce questo output:

argomenti dell'evento: (command=System.Data.SqlClient.SQLCommand commandType=2 status=0)

L'evento RowUpdated restituisce questo output:

event args: (command=System.Data.SqlClient.SQLCommand commandType=2 recordsAffected=1 row=System.Data.DataRow[37] status=0)

C#
// 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 CONNECTION_STRING = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer";
    const string SELECT_ALL = "select * from Products";

    //Create DataAdapter.
    SqlDataAdapter rAdapter    = new SqlDataAdapter(SELECT_ALL, CONNECTION_STRING);

    //Create and fill DataSet (Select only first 5 rows.).
    DataSet rDataSet = new DataSet();
    rAdapter.Fill(rDataSet, 0, 5, "Table");

    //Modify DataSet.
    DataTable rTable = rDataSet.Tables["Table"];
    rTable.Rows[0][1] = "new product";

    //Add handlers.
    rAdapter.RowUpdating += new SqlRowUpdatingEventHandler( OnRowUpdating );
    rAdapter.RowUpdated += new SqlRowUpdatedEventHandler( OnRowUpdated );

    //Update--this operation fires two events (RowUpdating and RowUpdated) for each changed row.
    rAdapter.Update(rDataSet, "Table");

    //Remove handlers.
    rAdapter.RowUpdating -= new SqlRowUpdatingEventHandler( OnRowUpdating );
    rAdapter.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 + ")");
}

Commenti

L'evento RowUpdating viene generato prima Update di 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. Chiamata del metodo AcceptChanges.

Costruttori

Proprietà

BaseCommand

Ottiene o imposta l'oggetto IDbCommand per un'istanza di questa classe.

(Ereditato da RowUpdatingEventArgs)
Command

Ottiene o imposta l'oggetto SqlCommand da eseguire quando si esegue il metodo Update(DataSet).

Errors

Ottiene tutti gli errori generati dal provider di dati .NET al momento dell'esecuzione del metodo Command.

(Ereditato da RowUpdatingEventArgs)
Row

Ottiene la classe DataRow che viene inviata al server quale parte di un'operazione insert, update o delete.

(Ereditato da RowUpdatingEventArgs)
StatementType

Ottiene il tipo di istruzione SQL da eseguire.

(Ereditato da RowUpdatingEventArgs)
Status

Ottiene o imposta l'enumerazione UpdateStatus della proprietà Command.

(Ereditato da RowUpdatingEventArgs)
TableMapping

Ottiene l'oggetto DataTableMapping da inviare attraverso il metodo Update(DataSet).

(Ereditato da RowUpdatingEventArgs)

Metodi

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 l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a

Prodotto Versioni
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Vedi anche