0

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?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by mikev2
0

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";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.