Solved

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

Posted on 2006-06-23
1
419 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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