DataView filter similar to TOP 10 sql statement.

Hello,

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?

Thanks!
LVL 6
PoeticAudioAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

YZlatCommented:
here is the same thing using C#:

ArrayList list = new ArrayList();
foreach (DataViewRow dvRow in myDataView) {
 list.Add(dvRow);
 if (list.Count == 10) {
   goto exitMyFor;
 }
}
exitMyFor: ;
0
e1vCommented:
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();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.