SqlRowUpdatingEventArgs 클래스

정의

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

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
상속
SqlRowUpdatingEventArgs

예제

다음 예제에서는 둘 다 사용 하는 RowUpdatingRowUpdated 이벤트입니다.

RowUpdating 이벤트가이 출력을 반환 합니다.

이벤트 인수: (command=System.Data.SqlClient.SQLCommand commandType=2 상태=0)

RowUpdated 이벤트가이 출력을 반환 합니다.

이벤트 인수: (command=System.Data.SqlClient.SQLCommand commandType=2 recordsAffected=1 row=System.Data.DataRow[37] 상태=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경우 업데이트된 각 데이터 행에 대해 두 개의 이벤트가 발생합니다. 실행 순서는 다음과 같습니다.

  1. 값을 DataRow 매개 변수 값으로 이동 됩니다.

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

  3. 명령을 실행합니다.

  4. 명령이 로 FirstReturnedRecord설정되고 첫 번째 반환 결과가 에 DataRow배치되는 경우

  5. 에 배치 됩니다 출력 매개 변수가 있는 경우는 DataRow합니다.

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

  7. AcceptChanges을 호출합니다.

생성자

SqlRowUpdatingEventArgs(DataRow, IDbCommand, StatementType, DataTableMapping)

SqlRowUpdatingEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

BaseCommand

이 클래스의 인스턴스에 대한 IDbCommand 개체를 가져오거나 설정합니다.

(다음에서 상속됨 RowUpdatingEventArgs)
Command

SqlCommand를 수행하는 동안 실행할 Update(DataSet)를 가져오거나 설정합니다.

Errors

Command를 실행할 때 .NET 데이터 공급자가 생성하는 오류를 가져옵니다.

(다음에서 상속됨 RowUpdatingEventArgs)
Row

INSERT, UPDATE 또는 DELETE 작업의 일부로 서버에 전송될 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)

적용 대상

추가 정보