SqlDataSource.SelectCommandType Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy tekst we SelectCommand właściwości jest zapytaniem SQL, czy nazwą procedury składowanej.

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

Wartość właściwości

SqlDataSourceCommandType Jedna z wartości. Wartość domyślna Text to .

Przykłady

W poniższym przykładzie kodu pokazano, jak ustawić SelectCommand tekst na nazwę procedury składowanej i SelectCommandType właściwość na StoredProcedure wartość, aby pobrać dane z bazy danych Microsoft SQL Server i wyświetlić ją w kontrolceDropDownList.

<!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>

Uwagi

Właściwość SelectCommandType deleguje do SelectCommandType właściwości obiektu skojarzonego SqlDataSourceView z kontrolką SqlDataSource .

Dotyczy

Zobacz też