Solved

What is the previous or the next record in a database?

Posted on 2010-11-25
4
391 Views
Last Modified: 2012-05-10
Hi. I am using C# and MS Access database in a web site.

I filter one element and display it.

How do I know which is the previous element (to be able to make some navigation) or the next element. Also need to know if it is a first element (in this case there is no previous element) or the last element (so there is no next element.)

thx
0
Comment
Question by:kuzmar
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34214154
The only way you're going to do that is to retrieve 3 records, the one you want to display, plus the one before and after, because you will need the id's from them to determine next/prev.
0
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 34215119
Unless you use an autoincrementing column. Then you can guess the previous (it may have been deleted so just keep trying smaller and smaller numbers till you get a hit)
0
 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 total points
ID: 34215181
You need to build the paging logic here like this.

For ex There 5 records are in your data.

S.No      EmployeeId      EmployeeName    TotalCount
1                    E-1                     EName1                 5
2                    E-2                     EName2                 5
3                    E-3                     EName3                 5
4                    E-4                     EName4                 5
5                    E-5                     EName5                 5

Then you can write the logic to know first or last or in the middle.

1) if PageNum = 1 this is your first record(disable prev button)
2) if PageNum <> 1 and PageNum <> 5 , this is your middle of the page(i.e 2,3,4)(enable both prev, next buttons)
3) if PageNum <> 1 and PageNum = 5 , this is your last page(disable next button)

Where 5 is your total record count.


0
 

Author Comment

by:kuzmar
ID: 34215753
totaly forgot about it... thx
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

749 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