I'm trying to populate datagrid with only 5 newest results from access database. I have tried using TOP 5 parameter but for some reason it gave 5 last results and not 5 newest. And if i put order by desc, it would show the newest, but the newest result was on the top of the datagrid, and not at the bottom as it should be. And also, there was 6 results for reason, i dont know why. Here is the sql syntax i tried:

strSQL = "SELECT TOP 5 * FROM [" + DropDownList2.SelectedValue + "] WHERE HOLE_ID = '" + DropDownList1.SelectedValue + "' ORDER BY DATE_START DESC";

How should i modify my code, so that it would show 5 latest results by date, and would show them in a way that the newest one is at the bottom?

This will first select the top 5 records in the wrong order into the innermost select, call that table 'a' and then re-order that table for the result that's returned...

strSQL = "SELECT * FROM (SELECT TOP 5 * FROM [" + DropDownList2.SelectedValue + "] WHERE HOLE_ID = '" + DropDownList1.SelectedValue + "' ORDER BY DATE_START DESC) a ORDER BY a.DATE_START";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.