SqlDataSourceCommandEventArgs SqlDataSourceCommandEventArgs SqlDataSourceCommandEventArgs SqlDataSourceCommandEventArgs Class

정의

Updating 컨트롤의 Deleting, InsertingSqlDataSource 이벤트에 대한 데이터를 제공합니다.Provides data for the Updating, Deleting and Inserting events of the SqlDataSource control.

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

예제

다음 코드 예제에는 Microsoft SQL Server 데이터베이스에서 검색 된 데이터를 표시 하는 방법을 보여 줍니다.는 DropDownList 컨트롤을 사용 하 여 레코드 업데이트는 TextBox 제어 합니다.The following code example demonstrates how to display data retrieved from a Microsoft SQL Server database in a DropDownList control, and update the record using a TextBox control. 예제를 사용 하는 방법을 보여 줍니다는 DbTransaction 사용 하는 경우 트랜잭션 컨텍스트를 추가 하는 개체는 SqlDataSource 데이터를 업데이트 하도록 컨트롤을 합니다.The example shows how you can use a DbTransaction object to add transaction context when using the SqlDataSource control to update data.

<%@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 이벤트에 필요한 추가 전처리 수행 하거나 완전히 데이터베이스 명령을 취소할 수 있습니다.By adding an event handler delegate to handle the Updating, Inserting, or Deleting events, you can perform any additional preprocessing required or cancel the database command entirely.

때문에 SqlDataSourceCommandEventArgs 에서 파생 된 클래스를 CancelEventArgs 클래스를 취소할 수 있습니다는 보류 중인 SqlDataSource 명령을 설정 하 여 데이터베이스를 Cancel 속성을 true.Because the SqlDataSourceCommandEventArgs class is derived from the CancelEventArgs class, you can cancel a pending SqlDataSource database command by setting the Cancel property to true. 검토 하 고 조작할 수는 CommandText, Parameters 컬렉션과 다른 명령 속성에 액세스 하 여 명령을 실행 하기 전에 DbCommand 에서 노출 된 개체는 Command 속성입니다.You can examine and manipulate the CommandText, Parameters collection, and other command properties prior to running the command by accessing the DbCommand object exposed by the Command property.

SqlDataSourceCommandEventArgs 클래스는를 OnUpdating, OnInserting, 및 OnDeleting 에 대 한 액세스를 제공 하는 메서드를 SqlDataSource 데이터베이스 명령을 실행 하기 전에 합니다.The SqlDataSourceCommandEventArgs class is used in the OnUpdating, OnInserting, and OnDeleting methods to provide access to a SqlDataSource database command before it is run. SqlDataSource 컨트롤 데이터 작업을 사용 하는 동안 기본 데이터 개체를 사용 하 여 작업을 처리할 수 있는 많은 이벤트를 노출 합니다.The SqlDataSource control exposes many events that you can handle to work with the underlying data objects during the course of a data operation. 다음 표에서 이벤트를 나열 하 고 연결 된 EventArgs 및 이벤트 처리기 클래스를 사용 하 여 데이터 작업의 수명 주기에 해당 하는 다양 한 이벤트를 소개 하기 위해는 SqlDataSource 제어 합니다.The following table lists the events and associated EventArgs and event handler classes, to better guide you to the various events that correspond to the lifecycle of a data operation using the SqlDataSource control.

이벤트Event EventArgsEventArgs 이벤트 처리기EventHandler
Selecting 데이터를 검색 하기 전에 발생 합니다.Selecting occurs before the data is retrieved. SqlDataSourceSelectingEventArgs SqlDataSourceSelectingEventHandler
Inserting하십시오 Updating, Deleting 업데이트 또는 삭제 작업이 수행 되는 삽입 하기 전에 발생 합니다.Inserting, Updating, Deleting occur before an insert, update, or delete operation is performed. SqlDataSourceCommandEventArgs SqlDataSourceCommandEventHandler
SelectedInserted, Updated, Deleted 데이터 검색, 삽입, 업데이트 후에 발생 또는 삭제 작업을 완료 합니다.Selected, Inserted, Updated, Deleted occur after the data retrieval, insert, update, or delete operations completes. SqlDataSourceStatusEventArgs SqlDataSourceStatusEventHandler

생성자

SqlDataSourceCommandEventArgs(DbCommand) SqlDataSourceCommandEventArgs(DbCommand) SqlDataSourceCommandEventArgs(DbCommand) SqlDataSourceCommandEventArgs(DbCommand)

지정된 데이터베이스 명령 개체를 사용하여 SqlDataSourceCommandEventArgs 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the SqlDataSourceCommandEventArgs class, using the specified database command object.

속성

Cancel Cancel Cancel Cancel

이벤트를 취소해야 할지 여부를 나타내는 값을 가져오거나 설정합니다.Gets or sets a value indicating whether the event should be canceled.

(Inherited from CancelEventArgs)
Command Command Command Command

보류 중인 데이터베이스 명령을 가져옵니다.Gets the pending database command.

메서드

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

적용 대상

추가 정보