Source view of SQLDATASOURCE.ASPX
DotNet Funda: Code Viewer
sqldatasource.aspx | sqldatasource.aspx.cs
Close Window  
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHeader" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderForTitleAndIntro" Runat="Server">
    <table width="100%" cellpadding="2" cellspacing="0">
        <tr valign="top" class="ArticleTitle">
            <td style="padding-left:10px;" valign="middle">
                asp:SqlDataSource control</td>
        </tr>
        <tr>
            <td class="ArticleContents">
                SqlDataSource control is a data source control that is used to connect to a relational database.
            </td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;</td>
        </tr>
    </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderForContents" Runat="Server">
    <div class="ArticleContents">
        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.
        <p>&nbsp;</p>
        
        <a name="#prop">Following are some important properties that are very useful.</a>
        <table width="100%" class="TutoPropPlaceHolder" border="1" cellpadding="2" cellspacing="1">
            <tr>
                <th colspan="2" align="left">
                    Properties for Configuring Data Source
                </th>
            </tr>
            <tr>
                <td class="DemoCP">InsertCommand, InsertParameters, InsertCommandType</td>
                <td>
                    Gets or sets the SQL Statement, parameter and type of command (text or stored procedure) to insert a record.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">DeleteCommand, DeleteParameters, DeleteCommandType</td>
                <td>
                    Gets or sets the SQL Statement, parameters and type of the command (text or stored procedure) to delete a record.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">UpdateCommand, UpdateParameters, UpdateCommandType</td>
                <td>
                    Gets or sets the SQL Statement, parameters and type of the command (text or stored procedure) to update a record.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">SelectCommand, SelectParameters, SelectCommandType</td>
                <td>
                    Gets or sets the SQL Statement, parameters and type of the command (text or stored procedure) to select record(s).
                </td>
            </tr>
            <tr>
                <th colspan="2" align="left">
                    Parameter Types of DataSource Controls
                </th>
            </tr>
            <tr>
                <td class="DemoCP">ControlParameter</td>
                <td>
                    Gets the value from any public property of the server control.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">FormParameter</td>
                <td>
                    Gets the value of any input field from the form.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">QueryStringParameter</td>
                <td>
                    Gets the value from specified querystring.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">Parameter</td>
                <td>
                    Gets the parameter value assigned in the code.
                </td>
            </tr>
            <tr>
                <th colspan="2" align="left">
                    Other Properties of SqlDataSource Control
                </th>
            </tr>
            <tr>
                <td class="DemoCP">ProviderName</td>
                <td>
                    Gets or sets the .NET ProviderName name.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">DataSourceMode</td>
                <td>
                    DataSet/DataReader. Used to specify the data source mode. 
                    In case of DataReader paging is not supported in the target control (GridView etc.).
                </td>
            </tr>
            <tr>
                <td class="DemoCP">ConnectionString</td>
                <td>
                    Gets or sets the connection string to connect to the database.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">ConflictDetection</td>
                <td>
                    CompareAllValues/OverWriteChanges. Used to determine how conflict will be handled in case of updation or deletion of the records.
                </td>
            </tr>
            <tr>
                <th colspan="2" align="left">
                    Caching Properties of SqlDataSource Control
                </th>
            </tr>
            <tr>
                <td class="DemoCP">EnableCaching</td>
                <td>
                    true/false. Used to indicate whether enable caching or not.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">CacheDuration</td>
                <td>
                    Used to indicate number of seconds the data shoud be maintained in the cache.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">CacheExpirationPolicy</td>
                <td>
                    Absolute/Sliding. Used to indicate if the cache policy is absolute or sliding. <br />
                    Absolute: The data is removed after specified duration. Sliding: The data is removed if it is not used for specified duration.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">EnableCaching</td>
                <td>
                    true/false. Used to indicate whether enable caching or not.
                </td>
            </tr>
        </table>
        <!-- START - Demo Section -->
        <table class="DemoPlaceHolder" border="1" cellpadding="2" cellspacing="4">
            <tr>
                <td class="DemoTitle">
                    DEMO : SqlDataSource
                </td>
                <td align="right">
                    <a class="DemoShowSource" href="../../misc/codeviewer/default.aspx?pagename=~/tutorials/controls/sqldatasource.aspx" target="_blank">Show Source Code</a>
                </td>
            </tr>
            <tr>
                <td>
                    <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>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:ConnStr %>'
                     SelectCommand="Select * FROM SampleForTutorials ORDER BY [Name]" DataSourceMode="DataSet">
                     </asp:SqlDataSource>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <!-- START - Server Side Code -->
                    <pre>
    
    // DetailsView Control ///////////////////////////////                    
    &lt;asp:DetailsView ID="DetailsView1" runat="Server" CellPadding="4" ForeColor="#333333" GridLines="None"
     Width="100%" DataSourceID="SqlDataSource1" AllowPaging="True" AutoGenerateRows="True" DataKeyNames="AutoID"&gt;
        &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
        &lt;CommandRowStyle BackColor="#E2DED6" Font-Bold="True" /&gt;
        &lt;EditRowStyle BackColor="#999999" /&gt;
        &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" /&gt;
        &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt;
        &lt;FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" /&gt;
        &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
        &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt;
    &lt;/asp:DetailsView&gt;
    
    
    // SqlDataSource Control ///////////////////////////////
    &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='&lt;%$ ConnectionStrings:ConnStr %&gt;'
     SelectCommand="Select * FROM SampleForTutorials ORDER BY [Name]" DataSourceMode="DataSet"&gt;
     &lt;/asp:SqlDataSource&gt;                   
    </pre> 
                    <!-- END - Server Side Code -->
                </td>
            </tr>
        </table>
        <!-- END - Demo Section -->
        </div>
    <br />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderFooter" Runat="Server">
</asp:Content>

Go Top