Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-06-23
1
Medium Priority
?
441 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 150 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

885 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