Solved

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

Posted on 2010-11-25
4
387 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 38

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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 Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

863 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

24 Experts available now in Live!

Get 1:1 Help Now