DataView.RowFilter - Get top 5 rows

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
LVL 2
NugsAsked:
Who is Participating?
 
surajgupthaConnect With a Mentor Commented:
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
 
grayeConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.