SqlDataSourceStatusEventArgsとは? わかりやすく解説

SqlDataSourceStatusEventArgs クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

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

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class SqlDataSourceStatusEventArgs
    Inherits EventArgs
Dim instance As SqlDataSourceStatusEventArgs
public class SqlDataSourceStatusEventArgs :
 EventArgs
public ref class SqlDataSourceStatusEventArgs
 : public EventArgs
public class SqlDataSourceStatusEventArgs extends
 EventArgs
public class SqlDataSourceStatusEventArgs extends
 EventArgs
解説解説

SqlDataSourceStatusEventArgs クラスは、データ ソース コントロールによって実行されたデータベース操作の完了後、Selected、Updated、Inserted、Deleted の各イベントで、これらの操作に関する情報を渡すために使用されます。この情報には、操作によって影響を受けた行数、データ ソースが操作を実行するために使用した DbCommand オブジェクト、発生した例外情報などが含まれます。Selected、Updated、Inserted、Deleted の各イベントを処理するためのイベント ハンドラ デリゲートを追加することで、このデータをチェックして、必要な追加のポスト プロセスを実行できます。

SqlDataSource コントロールは、データ操作の過程で、基になるデータ オブジェクトを操作する際に利用できる、数多くのイベントを公開しています。次の表は、SqlDataSource コントロールを使用したデータ操作の一連の流れに対応するさまざまなイベントをわかりやすく紹介するために、各種のイベントと、個々のイベントに対応する EventArgs、およびイベント ハンドラ クラスをまとめたものです。

イベント

イベント引数

イベント ハンドラ

Selecting はデータが取得される前に発生します。

SqlDataSourceSelectingEventArgs

SqlDataSourceSelectingEventHandler

Inserting、Updating、および、Deleting は、それぞれ、挿入、更新、削除の各操作が実行される前に発生します。

SqlDataSourceCommandEventArgs

SqlDataSourceCommandEventHandler

Selected、Inserted、Updated、Deleted は、それぞれ、データの取得、挿入、更新、削除の各操作が完了した後で発生します。

SqlDataSourceStatusEventArgs

SqlDataSourceStatusEventHandler

使用例使用例

次のコード例は、SqlDataSource コントロールをストアド プロシージャで使用した後、その戻り値と出力パラメータの値を SqlDataSourceStatusEventArgs クラスを使ってチェックし、GridView コントロールに値を挿入する方法を示しています。ストアド プロシージャでは、GridView に表示するデータを選択しているほか、その他の情報 (整数の出力パラメータや戻り値など) を呼び出し元に返しています。SqlDataSource がストアド プロシージャで使用するパラメータは、Web フォームからの情報をストアド プロシージャに渡すためのパラメータと、フォームに情報を返すためのパラメータとで構成され、SelectParameters コレクションに格納されます。これらのパラメータの Direction プロパティは、Output および ReturnValue に設定されます。

<%@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>
  <body>
    <form 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="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>
  <body>
    <form 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>
.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
   System.EventArgs
    System.Web.UI.WebControls.SqlDataSourceStatusEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlDataSourceStatusEventArgs メンバ
System.Web.UI.WebControls 名前空間
SqlDataSourceStatusEventHandler
SqlDataSource クラス
SqlDataSource.Selected イベント
SqlDataSource.Updated イベント
SqlDataSource.Inserted イベント
SqlDataSource.Deleted イベント

SqlDataSourceStatusEventArgs コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

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

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    command As DbCommand, _
    affectedRows As Integer, _
    exception As Exception _
)
Dim command As DbCommand
Dim affectedRows As Integer
Dim exception As Exception

Dim instance As New SqlDataSourceStatusEventArgs(command,
 affectedRows, exception)
public SqlDataSourceStatusEventArgs (
    DbCommand command,
    int affectedRows,
    Exception exception
)
public:
SqlDataSourceStatusEventArgs (
    DbCommand^ command, 
    int affectedRows, 
    Exception^ exception
)
public SqlDataSourceStatusEventArgs (
    DbCommand command, 
    int affectedRows, 
    Exception exception
)
public function SqlDataSourceStatusEventArgs
 (
    command : DbCommand, 
    affectedRows : int, 
    exception : Exception
)

パラメータ

command

SqlDataSource コントロールによってデータベースに送信されるデータベース クエリ、コマンド、またはストアド プロシージャを表す DbCommand。

affectedRows

該当する場合は、データベース操作の影響を受けた行数。

exception

該当する場合は、データベース操作によってスローされた Exception。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlDataSourceStatusEventArgs クラス
SqlDataSourceStatusEventArgs メンバ
System.Web.UI.WebControls 名前空間
Command
AffectedRows

SqlDataSourceStatusEventArgs プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

SqlDataSourceStatusEventArgs クラス
System.Web.UI.WebControls 名前空間
SqlDataSourceStatusEventHandler
SqlDataSource クラス
SqlDataSource.Selected イベント
SqlDataSource.Updated イベント
SqlDataSource.Inserted イベント
SqlDataSource.Deleted イベント

SqlDataSourceStatusEventArgs メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

SqlDataSourceStatusEventArgs クラス
System.Web.UI.WebControls 名前空間
SqlDataSourceStatusEventHandler
SqlDataSource クラス
SqlDataSource.Selected イベント
SqlDataSource.Updated イベント
SqlDataSource.Inserted イベント
SqlDataSource.Deleted イベント

SqlDataSourceStatusEventArgs メンバ

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

SqlDataSourceStatusEventArgs データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド SqlDataSourceStatusEventArgs 指定された出力パラメータ、戻り値、および、データベース操作によって影響を受ける行数を使用して、SqlDataSourceStatusEventArgs クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

SqlDataSourceStatusEventArgs クラス
System.Web.UI.WebControls 名前空間
SqlDataSourceStatusEventHandler
SqlDataSource クラス
SqlDataSource.Selected イベント
SqlDataSource.Updated イベント
SqlDataSource.Inserted イベント
SqlDataSource.Deleted イベント



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「SqlDataSourceStatusEventArgs」の関連用語

SqlDataSourceStatusEventArgsのお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



SqlDataSourceStatusEventArgsのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS