User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 422,371 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,552 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Jan 31st, 2008
Views: 2,078
SelectTopFrom method gets the top rows from dataview or datatable
Last edited : Jan 31st, 2008.
csharp Syntax
  1. public static DataTable SelectTopFrom(DataTable dt, int rowCount)
  2. {
  3. DataTable dtn = dt.Clone();
  4. for (int i = 0; i < rowCount; i++)
  5. {
  6. dtn.ImportRow(dt.Rows[i]);
  7. }
  8. return dtn;
  9. }
  10.  
  11. public static DataView SelectTopFrom(DataView dv, int rowCount)
  12. {
  13. DataTable dt = CreateTable(dv);
  14. DataTable dtn = dt.Clone();
  15. for (int i = 0; i < rowCount; i++)
  16. {
  17. dtn.ImportRow(dt.Rows[i]);
  18. }
  19. DataView dvn = new DataView(dtn);
  20. return dvn;
  21. }
Comments (Newest First)
serkansendur | Posting Whiz in Training | Jan 31st, 2008
I forgot to write "CreateTable" method above, you can look at it in the snipped named "Convert DataView To DataTable".
I think it is better to seperate these two snippets
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 8:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC