News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

The SqlDataSource control used to display news articles

Started by thiruvasagamani, Mar 27, 2009, 02:45 PM

Previous topic - Next topic

thiruvasagamani

The SqlDataSource control used to display news articles

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
SelectCommand="PagedAnnouncementList" SelectCommandType="StoredProcedure"
OnSelected="SqlDataSource1_Selected">
   <SelectParameters>
      <asp:ControlParameter Name="pageNum" ControlID="pn1"
       PropertyName="SelectedPage" />
      <asp:Parameter DefaultValue="10" Name="pageSize" Type="Int32" />
      <asp:Parameter Name="pageCount" Direction="ReturnValue"
       Type="Int32" />
   </SelectParameters>
</asp:SqlDataSource>


From this listing, you can see that this SqlDataSource control is retrieving the connection string as was the case with the earlier SqlDataSource controls that we presented. It is getting the connection string from the <connectionStrings> section of the web.config file. It is interesting that this SqlDataSource control is using a stored procedure instead of using an inline Select statement. To use a stored procedure, the SqlDataSource control uses the SelectCommandType attribute and gives it a value of StoredProcedure. Once a stored procedure has been declared as the type of select operation that will be used, then you name the stored procedure as the value of the SelectCommand attribute, as is done in the above example. In this case, this SqlDataSource control says that for a Select command, the control should look to the PagedAnnouncementList stored procedure in the SQL Express file.

SOurce : MSDN
Thiruvasakamani Karnan