Share via


SqlRowUpdatedEventArgs 클래스

정의

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

public ref class SqlRowUpdatedEventArgs sealed : System::Data::Common::RowUpdatedEventArgs
public sealed class SqlRowUpdatedEventArgs : System.Data.Common.RowUpdatedEventArgs
type SqlRowUpdatedEventArgs = class
    inherit RowUpdatedEventArgs
Public NotInheritable Class SqlRowUpdatedEventArgs
Inherits RowUpdatedEventArgs
상속
SqlRowUpdatedEventArgs

예제

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

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

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

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

이벤트 인수: (command=Microsoft.Data.SqlClient.SqlCommand commandType=2 recordsAffected=1 row=System.Data.DataRow[37] 상태=0)

using Microsoft.Data.SqlClient;
using System.Xml;
using System.Data.Common;
using System.Windows.Forms;

public class Form1 : Form
{
    private DataSet DataSet1;
    private DataGrid dataGrid1;

    // 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 connectionString =
                  "Integrated Security=SSPI;database=Northwind;server=MSSQL1";
        const string queryString = "SELECT * FROMProducts";

        // create DataAdapter
        SqlDataAdapter adapter = new SqlDataAdapter(queryString, connectionString);
        SqlCommandBuilder builder = new SqlCommandBuilder(adapter);

        // Create and fill DataSet (select only first 5 rows)
        DataSet dataSet = new DataSet();
        adapter.Fill(dataSet, 0, 5, "Table");

        // Modify DataSet
        DataTable table = dataSet.Tables["Table"];
        table.Rows[0][1] = "new product";

        // add handlers
        adapter.RowUpdating += new SqlRowUpdatingEventHandler(OnRowUpdating);
        adapter.RowUpdated += new SqlRowUpdatedEventHandler(OnRowUpdated);

        // update, this operation fires two events 
        // (RowUpdating/RowUpdated) per changed row 
        adapter.Update(dataSet, "Table");

        // remove handlers
        adapter.RowUpdating -= new SqlRowUpdatingEventHandler(OnRowUpdating);
        adapter.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 + ")");
    }
}

설명

RowUpdated 이벤트는 때를 Update 행은 완료 합니다.

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

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

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

  3. 명령을 실행합니다.

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

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

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

  7. AcceptChanges을 호출합니다.

생성자

SqlRowUpdatedEventArgs(DataRow, IDbCommand, StatementType, DataTableMapping)

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

속성

Command

SqlCommand가 호출될 때 실행되는 Update(DataSet)를 가져오거나 설정합니다.

적용 대상