Solved

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

Posted on 2010-11-25
4
386 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
totaly forgot about it... thx
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

11 Experts available now in Live!

Get 1:1 Help Now