Question

I am using an Access database and I have an interface where users can delete and add records.

But I also have another aspect of my application where I need to display records one by one by binding them to a repeater, and for this I use a dataview and rowfilter. Originally I used the id field to indicate which row to display, incrementing it by one each time, but since users are able to delete records it doesn't work anymore since ids can jump and don't increment by one.

Is there anyway for me to do something that is like dbDataView.table.row(i) and increment i each time so that I can count through the records and not the ids?

Was it helpful?

Solution

If you know the id value for the current row, you can ask the db engine for the next (undeleted) row whose id is greater than the current id but less than all the rest. Access SQL provides a DMin Function which can make this easy. Substitute the current id value for x in this query ...

SELECT *
FROM YourTable
WHERE id = DMin('id', 'YourTable', 'id > x');

Convert that to a parameter query.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top