Click here to Skip to main content
11,581,852 members (79,490 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET
hello....How can I limit the no.of records in a dataset???
Posted 15-Nov-12 19:20pm
Nandakishorerao at 16-Nov-12 2:59am
The better Option is to limit the no of records in Your Query..Using Top Clause in sql.
Follow this Referrals:
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

If you provide one scenario, it will be easier to answer your question. I don't think dataset has such a property to limit the number of records. While copying records to a dataset, we can set the number of records to be copied to the dataset.
For example we can use 'Take' method in LINQ .[^]

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

DataView dataView = new DataView(dataTable);
dataView.RowFilter = String.Format("EventDate > '{0}'", DateTime.Now);
dataView.Sort = "EventDate";
dataTable = dataView.ToTable();
while (dataTable.Rows.Count > _rowLimit)
    dataTable = dataTable.AsEnumerable().Skip(0).Take(50).CopyToDataTable();
return dataTable;

I forgot to say
You'll need namespace: System.Linq and System.Data

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 345
1 Sergey Alexandrovich Kryukov 220
2 Andy Lanng 114
3 virusstorm 109
4 Kornfeld Eliyahu Peter 90
0 OriginalGriff 1,358
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 671
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 448

Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100