ASP.Net - SQLDataSource

A SQLDataSource control is used to bind data to a control. Myself, I perfer to use the ObjectDataSource control. But this is simpler to use.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<asp:DropDownList 
ID="dropOptions"
runat="server"
AppendDataBoundItems="True"
DataSourceID="dataOptions"
DataTextField="Full_Name"
DataValueField="empUserName"
Visible="False">
</asp:DropDownList>
<asp:SqlDataSource
ID="dataOptions"
runat="server"
ConnectionString="<%$ ConnectionStrings:TheConnectionString %>"
SelectCommand="SELECT [empUserName], [Full_Name], [CntyHireDate] FROM [v_Employee_Flattened_AllActive] WHERE ([CntyHireDate] &gt;= @CntyHireDate) or CntyHireDate is null">
<SelectParameters>
<asp:Parameter Name="CntyHireDate" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>

In this example, the data source is a SQLDataSource control. The control is bound to a DropDownList control. The control is bound to the data source by setting the DataSourceID property. The control is bound to the data source by setting the DataTextField and DataValueField properties. The control is bound to the data source by setting the AppendDataBoundItems property. The control is bound to the data source by setting the Visible property.

The SQLDataSource control also allows the addition of an update, insert, and delete command allowing you to to setup a control that can be used to update, insert, and delete data..

I perfer to use the ObjectDataSource control, because you can add a business object to the control. This allows you to use the business object to perform the validations that cannot be performed by the SQLDataSource control..