Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 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