SqlRowUpdatedEventArgs Class
Provides data for the RowUpdated event. This class cannot be inherited.
For a list of all members of this type, see SqlRowUpdatedEventArgs Members.
System.Object
System.EventArgs
System.Data.Common.RowUpdatedEventArgs
System.Data.SqlClient.SqlRowUpdatedEventArgs
[Visual Basic] NotInheritable Public Class SqlRowUpdatedEventArgs Inherits RowUpdatedEventArgs [C#] public sealed class SqlRowUpdatedEventArgs : RowUpdatedEventArgs [C++] public __gc __sealed class SqlRowUpdatedEventArgs : public RowUpdatedEventArgs [JScript] public class SqlRowUpdatedEventArgs extends RowUpdatedEventArgs
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
The RowUpdated event is raised when an Update to a row is completed.
When using Update, there are two events that occur for each data row updated. The order of execution is as follows:
- The values in the DataRow are moved to the parameter values.
- The OnRowUpdating event is raised.
- The command executes.
- If the command is set to FirstReturnedRecord, then the first returned result is placed in the DataRow.
- If there are output parameters, they are placed in the DataRow.
- The OnRowUpdated event is raised.
- AcceptChanges is called.
Example
[Visual Basic, C#, C++] The following example shows how to use both the RowUpdating and RowUpdated events.
[Visual Basic, C#, C++] The RowUpdating event returns this output:
[Visual Basic, C#, C++] event args: (command=System.Data.SqlClient.SqlCommand commandType=2 status=0)
[Visual Basic, C#, C++] The RowUpdated event returns this output:
[Visual Basic, C#, C++] event args: (command=System.Data.SqlClient.SqlCommand commandType=2 recordsAffected=1 row=System.Data.DataRow[37] status=0)
[Visual Basic] ' handler for RowUpdating event Protected Shared Sub OnRowUpdating(sender As Object, e As SqlRowUpdatingEventArgs) PrintEventArgs(e) End Sub 'OnRowUpdating ' handler for RowUpdated event Protected Shared Sub OnRowUpdated(sender As Object, e As SqlRowUpdatedEventArgs) PrintEventArgs(e) End Sub 'OnRowUpdated '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) Dim cb As SqlCommandBuilder = New SqlCommandBuilder(rAdapter) ' 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/RowUpdated) per changed row rAdapter.Update(rDataSet, "Table") ' remove handlers RemoveHandler rAdapter.RowUpdating, AddressOf OnRowUpdating RemoveHandler rAdapter.RowUpdated, AddressOf OnRowUpdated Return 0 End Function 'Main Overloads Protected 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 'PrintEventArgs Overloads Protected 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 'PrintEventArgs End Class 'Form1 [C#] // handler for RowUpdating event protected static void OnRowUpdating(object sender, SqlRowUpdatingEventArgs e) { PrintEventArgs(e); } // handler for RowUpdated event protected static void OnRowUpdated(object sender, SqlRowUpdatedEventArgs e) { PrintEventArgs(e); } public static int Main(String[] args) { 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); SqlCommandBuilder cb = new SqlCommandBuilder(rAdapter); // 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/RowUpdated) per changed row rAdapter.Update(rDataSet, "Table"); // remove handlers rAdapter.RowUpdating -= new SqlRowUpdatingEventHandler( OnRowUpdating ); rAdapter.RowUpdated -= new SqlRowUpdatedEventHandler( OnRowUpdated ); return 0; } protected static void PrintEventArgs(SqlRowUpdatingEventArgs args) { Console.WriteLine("OnRowUpdating"); Console.WriteLine(" event args: ("+ " command=" + args.Command + " commandType=" + args.StatementType + " status=" + args.Status + ")"); } protected static void PrintEventArgs(SqlRowUpdatedEventArgs args) { Console.WriteLine("OnRowUpdated"); Console.WriteLine( " event args: ("+ " command=" + args.Command + " commandType=" + args.StatementType + " recordsAffected=" + args.RecordsAffected + " status=" + args.Status + ")" ); } [C++] protected: // handler for RowUpdating event static void OnRowUpdating(Object* /*sender*/, SqlRowUpdatingEventArgs* e) { PrintEventArgs(e); } // handler for RowUpdated event static void OnRowUpdated(Object* /*sender*/, SqlRowUpdatedEventArgs* e) { PrintEventArgs(e); } public: static int Main() { String* CONNECTION_STRING = S"Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer"; String* SELECT_ALL = S"select * from Products"; // create DataAdapter SqlDataAdapter* rAdapter = new SqlDataAdapter(SELECT_ALL, CONNECTION_STRING); SqlCommandBuilder* cb = new SqlCommandBuilder(rAdapter); // Create and fill dataset (select only first 5 rows) DataSet* rDataSet = new DataSet(); rAdapter->Fill(rDataSet, 0, 5, S"Table"); // Modify dataSet DataTable* rTable = rDataSet->Tables->Item[S"Table"]; rTable->Rows->Item[0]->Item[1] = S"new product"; // add handlers rAdapter->RowUpdating += new SqlRowUpdatingEventHandler(0, OnRowUpdating ); rAdapter->RowUpdated += new SqlRowUpdatedEventHandler(0, OnRowUpdated ); // update, this operation fires two events (RowUpdating/RowUpdated) per changed row rAdapter->Update(rDataSet, S"Table"); // remove handlers rAdapter->RowUpdating -= new SqlRowUpdatingEventHandler(0, OnRowUpdating ); rAdapter->RowUpdated -= new SqlRowUpdatedEventHandler(0, OnRowUpdated ); return 0; } protected: static void PrintEventArgs(SqlRowUpdatingEventArgs* args) { Console::WriteLine(S"OnRowUpdating"); Console::WriteLine(String::Format( S" event args: ( command={0} commandType={1} status={2})", args->Command, __box(args->StatementType), __box(args->Status))); } static void PrintEventArgs(SqlRowUpdatedEventArgs* args) { Console::WriteLine(S"OnRowUpdated"); Console::WriteLine(String::Concat( String::Format( S" event args: ( command={0} commandType={1} ", args->Command, __box(args->StatementType) ), String::Format( S"recordsAffected={0} status={1})", __box(args->RecordsAffected), __box(args->Status) ))); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Data.SqlClient
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: System.Data (in System.Data.dll)
See Also
SqlRowUpdatedEventArgs Members | System.Data.SqlClient Namespace