Solved

How to use rowfilter property of dataview object to fetch last 'n' records

Posted on 2006-06-23
1
430 Views
Last Modified: 2012-08-14
How to use rowfilter property of dataview object to fetch last 'n' records in the dataview (to fetch last 5 records for example)


String str = "string that fetches last 5 records in customView?"

DataView customView = myDataSet.tables["sometable"].DefaultView;
customView.RowFilter = str;

thanks for help!
0
Comment
Question by:ugougbor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
mistaeverly earned 50 total points
ID: 16974299
As far as I know, you can't do that from the RowFilter.  One way you could do it would be to add a new column to the original DataTable, setting it as an AutoIncrement column.  Then once you create your dataview you could use this new column to filter out specific ranges of rows.

Personally, I have always found the following fast enough for my uses:

DataTable filteredDataTable = myDataSet.Tables["sometable"].Clone();
int numberOfRows=myDataSet.Tables["sometable"].Rows.Count;
for (int counter=Math.Max(numberOfRows-5,0); counter<numberOfRows; counter++)
{
    filteredDataTable.ImportRow(myDataSet.Tables["sometable"].Rows[counter]);
}

Now filteredDataTable has the last 5 (or less, if there are less than five rows in the original table) rows of the original DataTable.

Hope this helps.

Chad
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question