pagination working
(TODO: check for remaining pages)
This commit is contained in:
@@ -73,17 +73,17 @@ namespace StudentHouseDashboard.Repositories
|
||||
public List<User> GetUsersByPage(int? p, int? c)
|
||||
{
|
||||
List<User> users = new List<User>();
|
||||
if (c == null)
|
||||
if (c == null || c < 0)
|
||||
{
|
||||
c = 0;
|
||||
c = 10;
|
||||
}
|
||||
if (p == null)
|
||||
if (p == null || p < 0)
|
||||
{
|
||||
p = 0;
|
||||
}
|
||||
using (SqlConnection conn = CreateConnection())
|
||||
{
|
||||
string sql = "SELECT TOP(@count) * FROM Users WHERE ID > @start;";
|
||||
string sql = "SELECT * FROM Users ORDER BY ID OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;";
|
||||
SqlCommand sqlCommand = new SqlCommand(sql, conn);
|
||||
sqlCommand.Parameters.AddWithValue("@start", p * c);
|
||||
sqlCommand.Parameters.AddWithValue("@count", c);
|
||||
|
Reference in New Issue
Block a user