SqlDataSourceStatusEventArgs クラス

定義

データ操作の完了時に、SqlDataSource コントロールによって生成されたイベントのデータを提供します。

public ref class SqlDataSourceStatusEventArgs : EventArgs
public class SqlDataSourceStatusEventArgs : EventArgs
type SqlDataSourceStatusEventArgs = class
    inherit EventArgs
Public Class SqlDataSourceStatusEventArgs
Inherits EventArgs
継承
SqlDataSourceStatusEventArgs

次のコード例では、このクラスを使用して、ストアド プロシージャを使用 SqlDataSourceStatusEventArgs してコントロールを設定するときに SqlDataSource 返される出力パラメーターの戻り値と値を調べる方法を GridView 示します。 ストアド プロシージャは、に表示されるデータを GridView選択しますが、整数出力パラメーターや戻り値など、他の情報も呼び出し元に渡します。 ストアド プロシージャに SqlDataSource 使用するパラメーターはコレクションに SelectParameters 含まれており、Web フォームからストアド プロシージャに情報を渡すパラメーターと、フォームに情報を返すパラメーターで構成されます。 これらのパラメーターのプロパティは Direction 、and に Output 設定されます ReturnValue

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

<script runat="server">
// Clicking the Submit button explicitly refreshes the data 
// by calling the Select() method.
private void Submit(Object source, EventArgs e) {
  SqlDataSource1.Select(DataSourceSelectArguments.Empty);
}

// This event handler is called after the Select() method is executed.
private void OnSelectedHandler(Object source, SqlDataSourceStatusEventArgs e) {

  IDbCommand cmd = e.Command; 
  
  Label1.Text = "Parameter return values: ";

  foreach (SqlParameter param in cmd.Parameters) {
    //  Extract the value of the parameter.
    Label1.Text += param.ParameterName + " - " + param.Value.ToString();
  }
}
</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"
            datasourcemode="DataSet"
            connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
            selectcommand="getordertotal"
            onselected="OnSelectedHandler">
            <selectparameters>
              <asp:querystringparameter name="empId" querystringfield="empId" />
              <asp:parameter name="total" type="Int32" direction="Output" defaultvalue="0" />
              <asp:parameter name="_ret" type="Int32" direction="ReturnValue" defaultvalue="0" />
            </selectparameters>
        </asp:sqldatasource>
        <!--
          CREATE PROCEDURE dbo.getordertotal
            @empId int,
            @total int OUTPUT
          as
            set nocount on
            select @total    = count(1) from orders where employeeid=@empid;
            select * from orders where employeeID = @empId ;
            return (-1000);
          GO
        -->

        <asp:gridview
          id="GridView1"
          runat="server"
          allowpaging="True"
          pagesize="5"
          datasourceid="SqlDataSource1" />

        <asp:button
          id="Button1"
          runat="server"
          onclick="Submit"
          text="Refresh Data" />

        <asp:label id="Label1" runat="server" />

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

<script runat="server">
' Clicking the Submit button explicitly refreshes the data 
' by calling the Select() method.
Private Sub Submit(source As Object, e As EventArgs)
  
  SqlDataSource1.Select(DataSourceSelectArguments.Empty)
  
End Sub ' Submit

' This event handler is called after the Select() method is executed.
Private Sub OnSelectedHandler(source As Object, e As SqlDataSourceStatusEventArgs)

  Dim cmd As IDbCommand 
  cmd = e.Command
  Dim param As SqlParameter
  
  Label1.Text = "Parameter return values: "
  
  For Each param In cmd.Parameters
    
    ' Extract the name and value of the parameter.
    Label1.Text = Label1.Text & param.ParameterName & " - " & _
                  param.Value.ToString()

  Next

End Sub ' OnSelectedHandler
</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"
            datasourcemode="DataSet"
            connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
            selectcommand="getordertotal"
            onselected="OnSelectedHandler">
            <selectparameters>
              <asp:querystringparameter name="empId" querystringfield="empId" />
              <asp:parameter name="total" type="Int32" direction="Output" defaultvalue="0" />
              <asp:parameter name="_ret" type="Int32" direction="ReturnValue" defaultvalue="0" />
            </selectparameters>
        </asp:sqldatasource>
        <!--
          CREATE PROCEDURE dbo.getordertotal
            @empId int,
            @total int OUTPUT
          as
            set nocount on
            select @total    = count(1) from orders where employeeid=@empid;
            select * from orders where employeeID = @empId ;
            return (-1000);
          GO
        -->

        <asp:gridview
          id="GridView1"
          runat="server"
          allowpaging="True"
          pagesize="5"
          datasourceid="SqlDataSource1" />

        <asp:button
          id="Button1"
          runat="server"
          onclick="Submit"
          text="Refresh Data" />

        <asp:label id="Label1" runat="server" />

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

注釈

このSqlDataSourceStatusEventArgsクラスは、データ ソース コントロールによって実行された後に、データベース操作に関する情報を渡すために 、UpdatedInserted、およびDeletedイベントでSelected使用されます。 この情報には、操作の影響を受ける行数、操作の DbCommand 実行にデータ ソースが使用したオブジェクト、および結果として発生した例外情報が含まれます。 イベント を処理するイベント ハンドラー デリゲートをSelectedUpdatedInsertedDeleted追加することで、このデータを調べて、必要な追加の後処理を実行できます。

このコントロールは SqlDataSource 、データ操作の過程で基になるデータ オブジェクトを操作するために処理できる多くのイベントを公開します。 次の表は、コントロールを使用したデータ操作のライフ サイクルに対応するさまざまなイベントをより適切にガイドするために、イベントと関連する EventArgs イベント ハンドラー クラスの一覧です SqlDataSource

Event EventArgs EventHandler
Selecting は、データが取得される前に発生します。 SqlDataSourceSelectingEventArgs SqlDataSourceSelectingEventHandler
InsertingUpdating挿入 Deleting 、更新、または削除操作が実行される前に発生します。 SqlDataSourceCommandEventArgs SqlDataSourceCommandEventHandler
SelectedInsertedUpdatedデータ Deleted の取得、挿入、更新、または削除の操作が完了した後に発生します。 SqlDataSourceStatusEventArgs SqlDataSourceStatusEventHandler

コンストラクター

SqlDataSourceStatusEventArgs(DbCommand, Int32, Exception)

指定された出力パラメーター、戻り値、および、データベース操作によって影響を受ける行数を使用して、SqlDataSourceStatusEventArgs クラスの新しいインスタンスを初期化します。

プロパティ

AffectedRows

データベース操作の影響を受けた行の数を取得します。

Command

データベースに送信されたデータベース コマンドを取得します。

Exception

データ操作中にデータベースによってスローされる例外のラッパーを取得します。

ExceptionHandled

データベースによりスローされた例外が処理されたかどうか示す値を取得または設定します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください