Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
hello....How can I limit the no.of records in a dataset???
Posted 15 Nov '12 - 19:20

Comments
Nandakishorerao - 16 Nov '12 - 2:59
The better Option is to limit the no of records in Your Query..Using Top Clause in sql. Follow this Referrals: http://www.w3schools.com/sql/sql_top.asp

2 solutions

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
  Permalink  
Hi
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 .
 
http://msdn.microsoft.com/en-us/library/bb503062.aspx[^]
 
Regards
Dominic
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Mahesh Bailwal 373
1 Sergey Alexandrovich Kryukov 354
2 Maciej Los 245
3 Rohan Leuva 175
4 CPallini 175
0 Sergey Alexandrovich Kryukov 9,287
1 OriginalGriff 7,204
2 CPallini 3,923
3 Rohan Leuva 3,211
4 Maciej Los 2,713


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid