Solved

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

Posted on 2006-06-23
1
384 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now