DataView.RowFilter - Get top 5 rows

Posted on 2007-10-17
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?

            string FilterExpr = "";
            FilterExpr = "Fld_Cat = " + varCurCat;

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

            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,

Question by:Nugs
    LVL 21

    Accepted Solution

    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
    LVL 41

    Assisted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now