SqlDataSourceStatusEventArgs クラス
アセンブリ: System.Web (system.web.dll 内)
構文
解説SqlDataSourceStatusEventArgs クラスは、データ ソース コントロールによって実行されたデータベース操作の完了後、Selected、Updated、Inserted、Deleted の各イベントで、これらの操作に関する情報を渡すために使用されます。この情報には、操作によって影響を受けた行数、データ ソースが操作を実行するために使用した DbCommand オブジェクト、発生した例外情報などが含まれます。Selected、Updated、Inserted、Deleted の各イベントを処理するためのイベント ハンドラ デリゲートを追加することで、このデータをチェックして、必要な追加のポスト プロセスを実行できます。
SqlDataSource コントロールは、データ操作の過程で、基になるデータ オブジェクトを操作する際に利用できる、数多くのイベントを公開しています。次の表は、SqlDataSource コントロールを使用したデータ操作の一連の流れに対応するさまざまなイベントをわかりやすく紹介するために、各種のイベントと、個々のイベントに対応する EventArgs、およびイベント ハンドラ クラスをまとめたものです。
| 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 のセキュリティ
継承階層System.EventArgs
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs
スレッド セーフ
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照- SqlDataSourceStatusEventArgs クラスのページへのリンク