SqlDataSourceStatusEventArgs.Command プロパティ
アセンブリ: System.Web (system.web.dll 内)

データベースに送信されたデータベース コマンドを表す DbCommand オブジェクト。

SqlDataSource コントロールによって DbCommand がデータベースに送信された後、Selected、Updated、Inserted、Deleted の各イベントを処理することによって、このコントロールのプロパティをチェックしたり、操作したりできます。Command プロパティを使用すると、データベース操作の実行後に、Parameters プロパティで戻り値や出力パラメータの値にアクセスしたり、CommandText プロパティを使って、データベースに送信された SQL クエリ、コマンド、またはストアド プロシージャの名前を取得したりできます。
出力パラメータは、厳密には、Parameter オブジェクトの Direction プロパティに InputOutput または Output 値を持つパラメータから取得されます。戻り値は、ReturnValue 値を持つパラメータから取得されます。

SqlDataSource コントロールをストアド プロシージャで使用する場合に、出力パラメータの値をチェックする方法を次のコード例に示します。SqlDataSource がストアド プロシージャで使用するパラメータは、SelectParameters コレクションに格納され、Web フォームからの情報をストアド プロシージャに渡すためのパラメータと、フォームに情報を返すためのパラメータとで構成されます。このコード例は、SqlDataSourceStatusEventArgs クラスのトピックで取り上げているコード例の一部分です。
<%@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>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSqlDataSourceStatusEventArgs.Command プロパティを検索する場合は、下記のリンクをクリックしてください。

- SqlDataSourceStatusEventArgs.Command プロパティのページへのリンク