0

important: I'm using MS Acces, not because I want to. But because it's the only thing I've learned and I don't know how to work with other types of Databases and don't exactly have the time to learn to do it.

Okay so a bit of background info, I'm a student IT and I'm doing my internship, but because of Covid, I'm basically on my own; I'm writing a website on which images with titles and catagories have to be displayed, these images have to come from a database. Because the person for whom I'm writing the website knows nothing about coding I had to make a c# user interface application, for him to fill in the database. Now I'm only putting strings in this database, so instead of straight up images, it's more like image.jpg. But I need to put the data from the database into a list <string>, keep in mind I'm writing the website with C# ASP.NET. So I need this list in which I want all the string that are in one column of my table. To do this I figured I could make a for loop that would stop once there are no more records in the table. Now this loop worked sure, and everytime the loop restarts something would go into the list. Here is the code of that.

string amountRecordsStrg = "SELECT Count(Id) FROM TbGallerij;";
            int amountRecord = Convert.ToInt32(amountRecordsStrg);
            for(int i = 0; amountRecord > i; i++)
            {
                artTitel[i] = "SELECT tbGallerij.AfbeeldingTitel FROM tbGallerij;";
            }
        }

Now, the probLem I'm having is that I don't know how to select the specific record. by example: artTitel[2] = the fieldvalue in the column Afbeeldingtitel in the second record in the table tbGallerij

I looked up a bunch of things online, and found out about the existence of OFFSET and FETCH which should save me, exect for the fact that I don't know how to use it at all in access, it doesn't seem to work. Can anyone help me please? It's really important that I find a solution to this. I tried using the top keyword like suggested here MS Access LIMIT X, Y. But it didn't work and I also found the answer quite confusing and even after trying to analyze it, it didn't do what it had to do for me.

PS: I'm sorry if something in the text doesn't seem clear, if so please comment and I will edit it. I'm also sorry if the question isn't very clear. As you can see from my reputation, I'm not the greatest at asking questions/explaining things.

Summary: I need a way to select one specific record, such as the second record. Or the fifth record, and I can't just do this with the ID's because they change the whole time when records are deleted. Anything that could solve this would be greatly appreciated.

  • `LIMIT(X, Y)` (MySQL) is the same as `OFFSET X FETCH Y` (T-SQL) – Erik A Mar 02 '21 at 10:48
  • @ErikA it doesn't solve my question, it doesn't even work for me. And now I can't even ask my question again. Thanks a lot – StrangeITperson Mar 02 '21 at 12:30
  • See [“This question already has answers here” - but it does not. What can I do when I think my question's not a duplicate?](https://meta.stackoverflow.com/q/252252/7296893). Show you've tried to incorporate this solution, and share what went wrong. No need to be sassy – Erik A Mar 02 '21 at 12:37
  • @ErikA I'm just kind of panicking here because this is my last resort – StrangeITperson Mar 02 '21 at 12:44
  • Well, Stack Overflow is not a good place for seeking urgent help, unfortunately. And the problem is that Access just doesn't support pagination, so you'll have to use a workaround. I highly suggest you choose a different approach altogether, use [OleDbDataReader](https://learn.microsoft.com/en-us/dotnet/api/system.data.oledb.oledbdatareader) to retrieve all images at once, and then display them individually. If you're truly doing this for an internship, seek help at your college, because being left on your own as a student with tasks you're unfamiliar with is wrong. – Erik A Mar 02 '21 at 12:51
  • I'll try and figure this out, thanks – StrangeITperson Mar 02 '21 at 12:57
  • Is this a combobox? Review https://stackoverflow.com/questions/14747046/how-to-set-dropdownlist-value-in-asp-net-using-c-sharp – June7 Mar 02 '21 at 19:14
  • @June7 No it's not for a combobox, it's just to dynamically list items in a database on the website – StrangeITperson Mar 02 '21 at 20:51
  • List them into what? How should user select? Exactly what is issue? How to grab user selected item from the list string? How to apply that selection as a parameter in an SQL statement? – June7 Mar 02 '21 at 21:04
  • @june7 like I said, I need to get the data from the database from specific records into a list. The issue is making a query of a specific record, such as the fifth record, or the 11th record. But NOT with the ID because the ID doesn't always go like 1,2,3,4,5,etc. sometimes there are gaps because of edited/deleted records – StrangeITperson Mar 03 '21 at 22:50
  • So you have no problem with code seeing user selected item from list? Are you using an autonumber field in Access for record ID? Only approach I know is to use a unique record identifier as filter criteria. How you would include that identifier in the web list and then retrieve it to use as criteria is beyond me. – June7 Mar 04 '21 at 00:04
  • @June7 I decided to give MySql a shot now, so it doesn't matter anymore – StrangeITperson Mar 04 '21 at 15:35

0 Answers0