Share via


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

설명

합니다 RowUpdating 이벤트가 발생 하기 전에 Update 행입니다.

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

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

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

  3. 명령을 실행합니다.

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

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

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

  7. AcceptChanges을 호출합니다.

생성자

SqlRowUpdatingEventArgs(DataRow, IDbCommand, StatementType, DataTableMapping)

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

속성

Command

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

적용 대상