SqlDataSource.SelectCommandType プロパティ

定義

SelectCommand プロパティのテキストが SQL クエリまたは格納されたプロシージャの名前のいずれであるかを示す値を取得または設定します。

public:
 property System::Web::UI::WebControls::SqlDataSourceCommandType SelectCommandType { System::Web::UI::WebControls::SqlDataSourceCommandType get(); void set(System::Web::UI::WebControls::SqlDataSourceCommandType value); };
public System.Web.UI.WebControls.SqlDataSourceCommandType SelectCommandType { get; set; }
member this.SelectCommandType : System.Web.UI.WebControls.SqlDataSourceCommandType with get, set
Public Property SelectCommandType As SqlDataSourceCommandType

プロパティ値

SqlDataSourceCommandType 値のいずれか 1 つ。 既定値は、Text です。

次のコード例では、Microsoft SQL Server データベースからデータを取得してコントロールに表示するために、テキストをストアド プロシージャの名前に設定しSelectCommandType、 プロパティStoredProcedureを 値に設定SelectCommandする方法をDropDownList示します。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">

            <asp:DropDownList
                id="DropDownList1"
                runat="server"
                DataTextField="LastName"
                DataSourceID="SqlDataSource1" />

            <asp:SqlDataSource
                id="SqlDataSource1"
                runat="server"
                ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
                SelectCommandType="StoredProcedure"                
                SelectCommand="sp_lastnames">
            </asp:SqlDataSource>

            <!--
                The sp_lastnames stored procedure is
                CREATE PROCEDURE sp_lastnames AS
                   SELECT LastName FROM Employees
                GO
            -->

        </form>
    </body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">

            <asp:DropDownList
                id="DropDownList1"
                runat="server"
                DataTextField="LastName"
                DataSourceID="SqlDataSource1" />

            <asp:SqlDataSource
                id="SqlDataSource1"
                runat="server"
                ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
                SelectCommandType = "StoredProcedure"
                SelectCommand="sp_lastnames">
            </asp:SqlDataSource>

            <!--
                The sp_lastnames stored procedure is
                CREATE PROCEDURE sp_lastnames AS
                   SELECT LastName FROM Employees
                GO
            -->

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

注釈

プロパティは SelectCommandType 、コントロールに SelectCommandType 関連付けられている オブジェクトの SqlDataSourceView プロパティにデリゲートします SqlDataSource

適用対象

こちらもご覧ください