0

I am trying to skip the first 5 rows then fetch the next 5, i'm using this for a page system. However something is wrong with my command. I rarely use databases because I get lazy and I hope somebody can help me with this.

I've tried putting the brackets around the columns i'm selecting in case any were protected and I tried adding offset 5 rows to the end of the statement.

strSQL = "SELECT [ID], [AuthorName], [AuthorID], [Title], [Content], [Views], [Replies], [LatestTime] FROM [Threads] ORDER BY [ID] DESC offset 5 rows";

When I run this code I get an error page with the message:

IErrorInfo.GetDescription failed with E_FAIL(0x80004005).

and obviously the error is where the command is executing.

Erik A
  • 31,639
  • 12
  • 42
  • 67
  • I don't believe access supports `offset`. This is an old post but has some options: https://stackoverflow.com/questions/8627032/ms-access-limit-x-y – Ben Jun 04 '19 at 03:30
  • @Ben well i see that however, how will i choose between 2 numbers like 5,10 since it doesnt support limit either. – Logan Risen Jun 04 '19 at 03:36
  • You'll need to do some basic maths I guess. Depends on which approach you go with, but they all pretty much revolve around fetching X rows where X is the number you want to skip + the number you want to fetch, and then only taking the number you want to fetch. – Ben Jun 04 '19 at 03:39
  • In supplement to ben’s answer LINQ has skip and take methods you could use after downloading eg 10 rows. Can’t help but feel that access is the wrong database for this application though; building a UI that is paginating seems far more enterprise – Caius Jard Jun 04 '19 at 03:46

1 Answers1

0

I figured this out thanks to user https://stackoverflow.com/users/3401554/ben, what I did is not the most efficient it but it works for forums. I did my page number * the amount of threads per page, then I got the top records from the DB and skipped all the records in the reader till I reached the last 10.