I am trying to finish writting my news/blog ASP.net C# application and I am getting stuck on how to return only 10 items at a time after filtering items based on tag or keyword. This is an example of what I am looking for:
- User queries sql by browsing to ?tag=Pizza
- Backend finds all tags that equal the query string (sent over as a @ parameter). This part I have figured out.
Now I want it to just return 10 rows at a time from this filtered statement. I was easily able to do this with this when I wasn't filtering anything out:
sqlCommand.CommandText = "SELECT * FROM (SELECT row_number() over(ORDER BY news_id) AS row_number, * FROM news) T WHERE row_number BETWEEN (SELECT rowcnt FROM sys.sysindexes WHERE (id = OBJECT_ID('news')) AND (indid < 2))-(@start+10) AND (SELECT rowcnt FROM sys.sysindexes WHERE (id = OBJECT_ID('news')) AND (indid < 2))-(@start) ORDER BY news_id DESC"; sqlCommand.Parameters.Add("@start", SqlDbType.Int).Value = start;
I then display at the bottom of the page the user the option to view more. (This part is easy as I just need to add 10 to a query string of ?num=).
What is the best way to go about this goal?