DataView filter similar to TOP 10 sql statement.

Posted on 2006-04-18
Last Modified: 2008-02-01

I am using a dataview for filtering data, but i'm having a rough time trying to figure out how to do something similar to TOP in SQL. In SQL if you, say run a query that returns 50 dates, but you only want the top 10 you can do SELECT TOP 10 .....etc. Is there something similar I can do in a dataview?

Question by:PoeticAudio
    LVL 35

    Expert Comment

    LVL 35

    Expert Comment

    here is the same thing using C#:

    ArrayList list = new ArrayList();
    foreach (DataViewRow dvRow in myDataView) {
     if (list.Count == 10) {
       goto exitMyFor;
    exitMyFor: ;
    LVL 6

    Accepted Solution

    you cannot use TOP with rowfilter.
    If you have a identity key in your table you can do this to filter like TOP 10 : (here my identity column is called "Id")

    dataView.Sort = "Id ASC";
    dataView.RowFilter = "Id>=" + dv[0].Row["Id"].ToString();
    dataView.RowFilter += " AND Id<" + dv[10].Row["Id"].ToString();

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    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…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now