Solved

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

Posted on 2010-11-25
4
392 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
[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
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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
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…

717 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