SqlDataSource.SelectCommandType Proprietà

Definizione

Ottiene o imposta un valore indicante se il testo nella proprietà SelectCommand è una query SQL o il nome di una stored procedure.

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

Valore della proprietà

Uno dei valori di SqlDataSourceCommandType. Il valore predefinito è il valore Text.

Esempio

Nell'esempio di codice seguente viene illustrato come impostare il SelectCommand testo sul nome di una stored procedure e sulla SelectCommandType proprietà sul StoredProcedure valore, per recuperare i dati da un database Microsoft SQL Server e visualizzarlo in un DropDownList controllo.

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

Commenti

La SelectCommandType proprietà delega alla SelectCommandType proprietà dell'oggetto SqlDataSourceView associato al SqlDataSource controllo.

Si applica a

Vedi anche