SqlRowUpdatingEventArgs Classe
Definição
Fornece dados para o evento de RowUpdating .Provides data for the RowUpdating event.
public ref class SqlRowUpdatingEventArgs sealed : System::Data::Common::RowUpdatingEventArgs
public sealed class SqlRowUpdatingEventArgs : System.Data.Common.RowUpdatingEventArgs
type SqlRowUpdatingEventArgs = class
inherit RowUpdatingEventArgs
Public NotInheritable Class SqlRowUpdatingEventArgs
Inherits RowUpdatingEventArgs
- Herança
Exemplos
O exemplo a seguir mostra como usar os RowUpdating eventos e RowUpdated .The following example shows how to use both the RowUpdating and RowUpdated events.
O RowUpdating evento retorna esta saída:The RowUpdating event returns this output:
args de evento: (Command = System. Data. SqlClient. SQLCommand commandType = 2 status = 0)event args: (command=System.Data.SqlClient.SQLCommand commandType=2 status=0)
O RowUpdated evento retorna esta saída:The RowUpdated event returns this output:
args de evento: (Command = System. Data. SqlClient. SQLCommand commandType = 2 recordsAffected = 1 linha = System. Data. DataRow [37] status = 0)event args: (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 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 + ")");
}
'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
'Entry point which delegates to C-style main Private Function.
Public Overloads Shared Sub Main()
System.Environment.ExitCode = Main(System.Environment.GetCommandLineArgs())
End Sub
Overloads Public Shared Function Main(args() As String) As Integer
Const CONNECTION_STRING As String = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer"
Const SELECT_ALL As String = "select * from Products"
'Create DataAdapter.
Dim rAdapter As New SqlDataAdapter(SELECT_ALL, CONNECTION_STRING)
'Create and fill DataSet (Select only first 5 rows.).
Dim rDataSet As New DataSet()
rAdapter.Fill(rDataSet, 0, 5, "Table")
'Modify DataSet.
Dim rTable As DataTable = rDataSet.Tables("Table")
rTable.Rows(0)(1) = "new product"
'Add handlers.
AddHandler rAdapter.RowUpdating, AddressOf OnRowUpdating
AddHandler rAdapter.RowUpdated, AddressOf OnRowUpdated
'Update--this operation fires two events (RowUpdating and RowUpdated) for each changed row.
rAdapter.Update(rDataSet, "Table")
'Remove handlers.
RemoveHandler rAdapter.RowUpdating, AddressOf OnRowUpdating
RemoveHandler rAdapter.RowUpdated, AddressOf OnRowUpdated
Return 0
End Function
Overloads Private 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
Overloads Private 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
Comentários
O RowUpdating evento é gerado antes de um Update para uma linha.The RowUpdating event is raised before an Update to a row.
Quando você estiver usando o Update , haverá dois eventos que ocorrem para cada linha de dados atualizada.When you are using Update, there are two events that occur for each data row updated. A ordem de execução é a seguinte:The order of execution is as follows:
Os valores no DataRow são movidos para os valores de parâmetro.The values in the DataRow are moved to the parameter values.
O OnRowUpdating evento é gerado.The OnRowUpdating event is raised.
O comando é executado.The command executes.
Se o comando for definido como
FirstReturnedRecorde o primeiro resultado retornado será colocado no DataRow .If the command is set toFirstReturnedRecord, and the first returned result is placed in the DataRow.Se houver parâmetros de saída, eles serão colocados no DataRow .If there are output parameters, they are placed in the DataRow.
O OnRowUpdated evento é gerado.The OnRowUpdated event is raised.
AcceptChanges é chamado.AcceptChanges is called.
Construtores
| SqlRowUpdatingEventArgs(DataRow, IDbCommand, StatementType, DataTableMapping) |
Inicializa uma nova instância da classe SqlRowUpdatingEventArgs.Initializes a new instance of the SqlRowUpdatingEventArgs class. |
Propriedades
| BaseCommand |
Obtém ou define o objeto IDbCommand para uma instância desta classe.Gets or sets the IDbCommand object for an instance of this class. (Herdado de RowUpdatingEventArgs) |
| Command |
Obtém ou define o SqlCommand a ser executado ao realizar a Update(DataSet).Gets or sets the SqlCommand to execute when performing the Update(DataSet). |
| Errors |
Obtém erros gerados pelo provedor de dados .NET quando o Command é executado.Gets any errors generated by the .NET data provider when the Command executes. (Herdado de RowUpdatingEventArgs) |
| Row |
Obtém o DataRow que será enviado ao servidor como parte de uma operação de inserção, atualização ou exclusão.Gets the DataRow that will be sent to the server as part of an insert, update, or delete operation. (Herdado de RowUpdatingEventArgs) |
| StatementType |
Obtém o tipo de instrução SQL a ser executado.Gets the type of SQL statement to execute. (Herdado de RowUpdatingEventArgs) |
| Status |
Obtém ou define o UpdateStatus da propriedade Command.Gets or sets the UpdateStatus of the Command property. (Herdado de RowUpdatingEventArgs) |
| TableMapping |
Obtém o DataTableMapping a ser enviado por meio de Update(DataSet).Gets the DataTableMapping to send through the Update(DataSet). (Herdado de RowUpdatingEventArgs) |
Métodos
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |