SqlDataSourceCommandEventArgs 클래스

정의

Updating 컨트롤의 Deleting, InsertingSqlDataSource 이벤트에 대한 데이터를 제공합니다.

public ref class SqlDataSourceCommandEventArgs : System::ComponentModel::CancelEventArgs
public class SqlDataSourceCommandEventArgs : System.ComponentModel.CancelEventArgs
type SqlDataSourceCommandEventArgs = class
    inherit CancelEventArgs
Public Class SqlDataSourceCommandEventArgs
Inherits CancelEventArgs
상속
SqlDataSourceCommandEventArgs
파생

예제

다음 코드 예제에는 Microsoft SQL Server 데이터베이스에서 검색 된 데이터를 표시 하는 방법을 보여 줍니다.는 DropDownList 컨트롤을 사용 하 여 레코드 업데이트는 TextBox 제어 합니다. 예제를 사용 하는 방법을 보여 줍니다는 DbTransaction 사용 하는 경우 트랜잭션 컨텍스트를 추가 하는 개체는 SqlDataSource 데이터를 업데이트 하도록 컨트롤을 합니다.

<%@Page  Language="C#" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.Common" %>
<%@Import Namespace="System.Data.SqlClient" %>
<%@Import Namespace="System.Diagnostics" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

 private void On_Click(Object source, EventArgs e) {    
    SqlDataSource1.Update();
 }

 private void OnSqlUpdating(Object source, SqlDataSourceCommandEventArgs e) {
    DbCommand command = e.Command;
    DbConnection cx  = command.Connection;    
    cx.Open();    
    DbTransaction tx = cx.BeginTransaction();
    command.Transaction = tx;
 }

 private void OnSqlUpdated(Object source, SqlDataSourceStatusEventArgs e) {
    DbCommand command = e.Command;
    DbTransaction tx = command.Transaction;
    
    // In this code example the OtherProcessSucceeded variable represents
    // the outcome of some other process that occurs whenever the data is 
    // updated, and must succeed for the data change to be committed. For 
    // simplicity, we set this value to true. 
    bool OtherProcessSucceeded = true;
    
    if (OtherProcessSucceeded) {
        tx.Commit();
        Label2.Text="The record was updated successfully!";
    }
    else {
        tx.Rollback();
        Label2.Text="The record was not updated.";
    }
 }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT EmployeeID, LastName, Address FROM Employees"
          UpdateCommand="UPDATE Employees SET Address=@Address WHERE EmployeeID=@EmployeeID"
          OnUpdating="OnSqlUpdating"
          OnUpdated ="OnSqlUpdated">
          <UpdateParameters>
              <asp:ControlParameter Name="Address" ControlId="TextBox1" PropertyName="Text"/>
              <asp:ControlParameter Name="EmployeeID" ControlId="DropDownList1" PropertyName="SelectedValue"/>
          </UpdateParameters>
      </asp:SqlDataSource>

      <asp:DropDownList
          id="DropDownList1"
          runat="server"
          DataTextField="LastName"
          DataValueField="EmployeeID"
          DataSourceID="SqlDataSource1">
      </asp:DropDownList>

      <br />
      <asp:Label id="Label1" runat="server" Text="Enter a new address for the selected user."
        AssociatedControlID="TextBox1" />
      <asp:TextBox id="TextBox1" runat="server" />
      <asp:Button id="Submit" runat="server" Text="Submit" OnClick="On_Click" />

      <br /><asp:Label id="Label2" runat="server" Text="" />

    </form>
  </body>
</html>
<%@Page  Language="VB" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.Common" %>
<%@Import Namespace="System.Diagnostics" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

 Sub On_Click(ByVal source As Object, ByVal e As EventArgs)
        SqlDataSource1.Update()
 End Sub 'On_Click

 Sub On_Sql_Updating(ByVal source As Object, ByVal e As SqlDataSourceCommandEventArgs)
     Dim command as DbCommand
     Dim connection as DbConnection
     Dim transaction as DbTransaction
     
     command    = e.Command
     connection = command.Connection     
     connection.Open()     
     transaction = connection.BeginTransaction()
     command.Transaction = transaction
 
 End Sub 'On_Sql_Updating
 
 Sub On_Sql_Updated(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs)
 
    Dim command As DbCommand
    Dim transaction As DbTransaction
    
    command = e.Command
    transaction = command.Transaction
    
    ' In this code example the OtherProcessSucceeded variable represents
    ' the outcome of some other process that occurs whenever the data is 
    ' updated, and must succeed for the data change to be committed. For 
    ' simplicity, we set this value to true. 
    Dim OtherProcessSucceeded as Boolean = True
    
    If (OtherProcessSucceeded) Then
        transaction.Commit()
        Label2.Text="The record was updated successfully!"
    Else    
        transaction.Rollback()
        Label2.Text="The record was not updated."
    End If
 End Sub ' On_Sql_Updated
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT EmployeeID, LastName, Address FROM Employees"
          UpdateCommand="UPDATE Employees SET Address=@Address WHERE EmployeeID=@EmployeeID"
          OnUpdating="On_Sql_Updating"
          OnUpdated ="On_Sql_Updated">
          <UpdateParameters>
              <asp:ControlParameter Name="Address" ControlId="TextBox1" PropertyName="Text"/>
              <asp:ControlParameter Name="EmployeeID" ControlId="DropDownList1" PropertyName="SelectedValue"/>
          </UpdateParameters>
      </asp:SqlDataSource>

      <asp:DropDownList
          id="DropDownList1"
          runat="server"
          DataTextField="LastName"
          DataValueField="EmployeeID"
          DataSourceID="SqlDataSource1">
      </asp:DropDownList>

      <br />
      <asp:Label id="Label1" runat="server" Text="Enter a new address for the selected user."
        AssociatedControlID="TextBox1" />
      <asp:TextBox id="TextBox1" runat="server" />
      <asp:Button id="Submit" runat="server" Text="Submit" OnClick="On_Click" />

      <br /><asp:Label id="Label2" runat="server" Text="" />

    </form>
  </body>
</html>

설명

처리 하는 이벤트 처리기 대리자를 추가 하 여는 Updating, Inserting, 또는 Deleting 이벤트에 필요한 추가 전처리 수행 하거나 완전히 데이터베이스 명령을 취소할 수 있습니다.

때문에 SqlDataSourceCommandEventArgs 에서 파생 된 클래스를 CancelEventArgs 클래스를 취소할 수 있습니다는 보류 중인 SqlDataSource 명령을 설정 하 여 데이터베이스를 Cancel 속성을 true. 검토 하 고 조작할 수는 CommandText, Parameters 컬렉션과 다른 명령 속성에 액세스 하 여 명령을 실행 하기 전에 DbCommand 에서 노출 된 개체는 Command 속성입니다.

SqlDataSourceCommandEventArgs 클래스는를 OnUpdating, OnInserting, 및 OnDeleting 에 대 한 액세스를 제공 하는 메서드를 SqlDataSource 데이터베이스 명령을 실행 하기 전에 합니다. SqlDataSource 컨트롤 데이터 작업을 사용 하는 동안 기본 데이터 개체를 사용 하 여 작업을 처리할 수 있는 많은 이벤트를 노출 합니다. 다음 표에서 이벤트를 나열 하 고 연결 된 EventArgs 및 이벤트 처리기 클래스를 사용 하 여 데이터 작업의 수명 주기에 해당 하는 다양 한 이벤트를 소개 하기 위해는 SqlDataSource 제어 합니다.

이벤트 EventArgs 이벤트 처리기
Selecting 데이터를 검색 하기 전에 발생 합니다. SqlDataSourceSelectingEventArgs SqlDataSourceSelectingEventHandler
Inserting하십시오 Updating, Deleting 업데이트 또는 삭제 작업이 수행 되는 삽입 하기 전에 발생 합니다. SqlDataSourceCommandEventArgs SqlDataSourceCommandEventHandler
SelectedInserted, Updated, Deleted 데이터 검색, 삽입, 업데이트 후에 발생 또는 삭제 작업을 완료 합니다. SqlDataSourceStatusEventArgs SqlDataSourceStatusEventHandler

생성자

SqlDataSourceCommandEventArgs(DbCommand)

지정된 데이터베이스 명령 개체를 사용하여 SqlDataSourceCommandEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

Cancel

이벤트를 취소해야 할지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 CancelEventArgs)
Command

보류 중인 데이터베이스 명령을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보