Go to DotNetFunda.com
 Online : 1765 |  Welcome, Guest!   Login
 
<<= Please see left side tutorials menu.

  • Download the OOPS, ASP.NET and ADO.NET Training Videos for FREE, click here.


Silverlight Tutorials | Report a Bug in the Tutorial

Interesting?   Share and Bookmark this

asp:SqlDataSource control
SqlDataSource control is a data source control that is used to connect to a relational database.
 
SqlDataSource control is a data source control that is used to connect to a relational database. You can even connect to Oracle or any other data source that can be accessible through OLEDB and ODBC. ConnectionString and ProviderName are the two properties that is used to connect the database. The first one specify the connection string and second specify the provider name. By default the provider is System.Data.SqlClient, it means connect to Sql Server database.

 

Following are some important properties that are very useful.
Properties for Configuring Data Source
InsertCommand, InsertParameters, InsertCommandType Gets or sets the SQL Statement, parameter and type of command (text or stored procedure) to insert a record.
DeleteCommand, DeleteParameters, DeleteCommandType Gets or sets the SQL Statement, parameters and type of the command (text or stored procedure) to delete a record.
UpdateCommand, UpdateParameters, UpdateCommandType Gets or sets the SQL Statement, parameters and type of the command (text or stored procedure) to update a record.
SelectCommand, SelectParameters, SelectCommandType Gets or sets the SQL Statement, parameters and type of the command (text or stored procedure) to select record(s).
Parameter Types of DataSource Controls
ControlParameter Gets the value from any public property of the server control.
FormParameter Gets the value of any input field from the form.
QueryStringParameter Gets the value from specified querystring.
Parameter Gets the parameter value assigned in the code.
Other Properties of SqlDataSource Control
ProviderName Gets or sets the .NET ProviderName name.
DataSourceMode DataSet/DataReader. Used to specify the data source mode. In case of DataReader paging is not supported in the target control (GridView etc.).
ConnectionString Gets or sets the connection string to connect to the database.
ConflictDetection CompareAllValues/OverWriteChanges. Used to determine how conflict will be handled in case of updation or deletion of the records.
Caching Properties of SqlDataSource Control
EnableCaching true/false. Used to indicate whether enable caching or not.
CacheDuration Used to indicate number of seconds the data shoud be maintained in the cache.
CacheExpirationPolicy Absolute/Sliding. Used to indicate if the cache policy is absolute or sliding.
Absolute: The data is removed after specified duration. Sliding: The data is removed if it is not used for specified duration.
EnableCaching true/false. Used to indicate whether enable caching or not.
DEMO : SqlDataSource Show Source Code
AutoID421
Namefrom
Addressto
Phone23
Cityhyd
12345678910...
 
    
    // DetailsView Control ///////////////////////////////                    
    <asp:DetailsView ID="DetailsView1" runat="Server" CellPadding="4" ForeColor="#333333" GridLines="None"
     Width="100%" DataSourceID="SqlDataSource1" AllowPaging="True" AutoGenerateRows="True" DataKeyNames="AutoID">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <EditRowStyle BackColor="#999999" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:DetailsView>
    
    
    // SqlDataSource Control ///////////////////////////////
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:ConnStr %>'
     SelectCommand="Select * FROM SampleForTutorials ORDER BY [Name]" DataSourceMode="DataSet">
     </asp:SqlDataSource>                   
    




About Us | The Team | Advertise | Contact Us | Feedback | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found copied contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
All rights reserved to DotNetFunda.Com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)