简体   繁体   中英

Using More Than one query in a repeater

How to use more than one query in a repeater in asp.net. for eg i have this repeater below and i want to use category names in it also i want to use a query which will return me the count of categories in a table how will i do that.

Repeater.

   asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" 

asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT [CategoryID], [CategoryName], [Description], [Picture] FROM [Categories]"></asp:SqlDataSource>

You can write a nested query as follows:

SELECT [CategoryID], [CategoryName], [Description], [Picture], (SELECT COUNT(*) FROM SOURCE_TABLE_NAME WHERE [CategoryID]=a.[CategoryID]) as [CATCOUNT] FROM [Categories] a

Where SOURCE_TABLE_NAME is the table name from where you want category count to be taken.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM