| |||||||
SqlDataSource.SelectCommand PropertySystem.Web.UI.WebControls Namespace SqlDataSource Class .NET Framework version 2.0 Sets or retrieves the SQL string that the SqlDataSource control uses to retrieve data from the underlying database. Syntax
Property Value
The property is read/write with no default value. RemarksBecause different database products use different varieties of SQL, the syntax of the SQL string depends on the current ADO.NET provider being used, which is identified by the ProviderName property. If the SQL string is a parameterized query or command, the placeholder of the parameter also depends on the ADO.NET provider being used. For example, if the provider is the System.Data.SqlClient, which is the default provider for the SqlDataSource class, the placeholder of the parameter is However, if the provider is set to the System.Data.Odbc or System.Data.OleDb, the placeholder of the parameter is The SelectCommand property can be an SQL string or the name of a stored procedure, if the data source supports stored procedures. The SelectCommand property delegates to the SelectCommand property of the SqlDataSourceView object that is associated with the SqlDataSource control.
ExampleThe following code examples demonstrate how to set the SelectCommand property of an AccessDataSource control. Basically, retrieving data from a Microsoft Access database using the AccessDataSource control can be done in two ways:
In the first case, you specify the SQL query by setting the AccessDataSource control's SelectCommand property as shown in the following example. <asp:accessdatasource id="ProductType" runat="server" datafile="~/app_data/gear.mdb" selectcommand="SELECT distinct Type FROM Products" datasourcemode="DataReader" /> In the second case, you specify the name of the Microsoft Access query to execute as the value of the SelectCommand, and set the SelectCommandType property value to StoredProcedure, as shown in the following example. <asp:accessdatasource id="zipcodes" runat="server"
datafile="~/app_data/usa.mdb"
selectcommand="[Zipcodes By State and County]"
selectcommandtype="StoredProcedure">
<selectparameters>
<asp:controlparameter controlid="lstStates"
propertyname="SelectedValue" />
<asp:controlparameter controlid="lstCounties"
propertyname="SelectedValue" />
</selectparameters>
</asp:accessdatasource>
See Also |
| ||||||
Check out related books at Amazon
© 2000-2008 Rey Nuñez All rights reserved.
If you have any question, comment or suggestion
about this site, please send us a note
You can help support aspxtreme