Provides data for the RowUpdating event. This class cannot be inherited.
For a list of all members of this type, see SqlRowUpdatingEventArgs Members.
System.Object
System.EventArgs
System.Data.Common.RowUpdatingEventArgs
System.Data.SqlClient.SqlRowUpdatingEventArgs
[Visual Basic] NotInheritable Public Class SqlRowUpdatingEventArgs Inherits RowUpdatingEventArgs [C#] public sealed class SqlRowUpdatingEventArgs : RowUpdatingEventArgs [C++] public __gc __sealed class SqlRowUpdatingEventArgs : public RowUpdatingEventArgs [JScript] public class SqlRowUpdatingEventArgs extends RowUpdatingEventArgs
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
The RowUpdating event is raised before an Update to a row.
When using Update, there are two events that occur for each data row updated. The order of execution is as follows:
[Visual Basic, C#] The following example shows how to use both the RowUpdating and RowUpdated events.
[Visual Basic, C#] The RowUpdating event returns this output:
[Visual Basic, C#] event args: (command=System.Data.SqlClient.SQLCommand commandType=2 status=0)
[Visual Basic, C#] The RowUpdated event returns this output:
[Visual Basic, 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) '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 '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 [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); //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; } 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++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
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 - Windows CE .NET
Assembly: System.Data (in System.Data.dll)
SqlRowUpdatingEventArgs Members | System.Data.SqlClient Namespace