SqlRowUpdatingEventArgs 类    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 RowUpdating 事件提供数据。
public ref class SqlRowUpdatingEventArgs sealed : System::Data::Common::RowUpdatingEventArgspublic sealed class SqlRowUpdatingEventArgs : System.Data.Common.RowUpdatingEventArgstype SqlRowUpdatingEventArgs = class
    inherit RowUpdatingEventArgsPublic NotInheritable Class SqlRowUpdatingEventArgs
Inherits RowUpdatingEventArgs- 继承
示例
以下示例演示如何同时使用 RowUpdating 和 RowUpdated 事件。
事件 RowUpdating 返回以下输出:
event args: (command=System.Data.SqlClient.SQLCommand commandType=2 status=0)
事件 RowUpdated 返回以下输出:
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
注解
事件 RowUpdating 在 之前 Update 引发到一行。
使用 Update时,更新的每个数据行都会发生两个事件。 执行顺序如下:
- 中的 DataRow 值将移动到参数值。 
- 引发 OnRowUpdating 事件。 
- 命令执行。 
- 如果 命令设置为 - FirstReturnedRecord,并且第一个返回的结果将放在 中 DataRow。
- 如果有输出参数,则它们放置在 中 DataRow。 
- 引发 OnRowUpdated 事件。 
- 调用 AcceptChanges。 
构造函数
| SqlRowUpdatingEventArgs(DataRow, IDbCommand, StatementType, DataTableMapping) | 初始化 SqlRowUpdatingEventArgs 类的新实例。 | 
属性
| BaseCommand | 获取或设置此类的实例的 IDbCommand 对象。(继承自 RowUpdatingEventArgs) | 
| Command | 获取或设置进行 SqlCommand 时执行的 Update(DataSet)。 | 
| Errors | 获取当 Command 执行时 .NET 数据提供程序生成的任何错误。(继承自 RowUpdatingEventArgs) | 
| Row | 获取要作为插入、更新或删除操作的一部分发送到服务器的 DataRow。(继承自 RowUpdatingEventArgs) | 
| StatementType | 获取要执行的 SQL 语句的类型。(继承自 RowUpdatingEventArgs) | 
| Status | 获取或设置 UpdateStatus 属性的 Command。(继承自 RowUpdatingEventArgs) | 
| TableMapping | 获取要通过 DataTableMapping 发送的 Update(DataSet)。(继承自 RowUpdatingEventArgs) | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |