[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

DataView.RowFilter - Get top 5 rows

Posted on 2007-10-17
2
Medium Priority
?
1,422 Views
Last Modified: 2008-01-09
I'm doing a RowFilter on a Dataview but i want to get the top 5 rows with the highest value in a specific column. How do i do this?

------------------------------------------------------------------------------
...
            //FILTER FOR CURRENT CATAGORY
            //---------------------------
            string FilterExpr = "";
            FilterExpr = "Fld_Cat = " + varCurCat;

            DataView DataView1 = new DataView(TableAdapter);
            DataView1.RowFilter = FilterExpr;

            //FILTER TOP RATED PRODUCTS
            //-------------------------
            FilterExpr = "Fld_Rating = 10"; //<--- this is where i want to get the top 5 values in this column
            DataView1.RowFilter = FilterExpr;
...
------------------------------------------------------------------------------

Any help would be great,

Nugs
0
Comment
Question by:Nugs
2 Comments
 
LVL 21

Accepted Solution

by:
surajguptha earned 900 total points
ID: 20096094
Why dont you write a query to do the same instead of fetching everything in your dataadapter
If you are using Oracle you can say

select * from (select * from employee order by age desc) where rownum < 11
0
 
LVL 41

Assisted Solution

by:graye
graye earned 600 total points
ID: 20096216
No, the RowFilter property was not designed to do that...  It is more analogous to the WHERE clause of an SQL statement.

But as surajguptha has suggested, you can accomplish the same thing via an SQL select statement against the underlying database.   In Microsoft SQL "dialect", the SQL command would be like this:

   select top 5 * from employee order by age desc
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question