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?
 
e1vConnect With a Mentor Commented:
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
 
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
All Courses

From novice to tech pro — start learning today.