다음을 통해 공유


SqlRowUpdatingEventArgs 클래스

RowUpdating 이벤트에 대한 데이터를 제공합니다.

네임스페이스: System.Data.SqlClient
어셈블리: System.Data(system.data.dll)

구문

‘선언
Public NotInheritable Class SqlRowUpdatingEventArgs
    Inherits RowUpdatingEventArgs
‘사용 방법
Dim instance As SqlRowUpdatingEventArgs
public sealed class SqlRowUpdatingEventArgs : RowUpdatingEventArgs
public ref class SqlRowUpdatingEventArgs sealed : public RowUpdatingEventArgs
public final class SqlRowUpdatingEventArgs extends RowUpdatingEventArgs
public final class SqlRowUpdatingEventArgs extends RowUpdatingEventArgs

설명

행에 대한 Update 이전에 RowUpdating 이벤트가 발생합니다.

Update를 사용하면 업데이트되는 각 데이터 행에 대해 두 개의 이벤트가 발생합니다. 실행 순서는 다음과 같습니다.

  1. DataRow의 값이 매개 변수 값으로 이동합니다.

  2. OnRowUpdating 이벤트가 발생합니다.

  3. 명령이 실행됩니다.

  4. 명령이 FirstReturnedRecord로 설정되면 첫 번째 반환 결과가 DataRow에 배치됩니다.

  5. 출력 매개 변수가 있을 경우, 이러한 매개 변수는 DataRow에 배치됩니다.

  6. OnRowUpdated 이벤트가 발생합니다.

  7. AcceptChanges가 호출됩니다.

예제

다음 예제에서는 RowUpdatingRowUpdated 이벤트 모두를 사용하는 방법을 설명합니다.

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 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 
// 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 + ")");
}

상속 계층 구조

System.Object
   System.EventArgs
     System.Data.Common.RowUpdatingEventArgs
      System.Data.SqlClient.SqlRowUpdatingEventArgs

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

SqlRowUpdatingEventArgs 멤버
System.Data.SqlClient 네임스페이스