What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 29225 |  Welcome, Guest!   Register  Login
Home > Tutorials > ASP.NET Tutorials > SqlDataSource

Silverlight Tutorials | Report a Bug in the Tutorial
Found interesting? Add this to:


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
AutoID13360
Name 
Address 
Phone 
City 
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 | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 11:05:38 AM