Mid ADO.NET

Use Paging: Instead of loading all the records at once, retrieve data in chunks (or?

pages) using SQL's LIMIT, OFFSET, or TOP clauses. You can implement paging on

both the server side (in the SQL query) and the client side (in the ASP.NET

application).

Example (Using Paging in SQL):

string query = "SELECT * FROM Customers ORDER BY CustomerID OFFSET

@Offset ROWS FETCH NEXT @PageSize ROWS ONLY";

SqlCommand command = new SqlCommand(query, connection);

command.Parameters.AddWithValue("@Offset", pageNumber * pageSize);

command.Parameters.AddWithValue("@PageSize", pageSize);

connection.Open();

SqlDataReader reader = command.ExecuteReader();

while (reader.Read())

// Process data

Follow:

reader.Close();

connection.Close();

More from ADO.NET Core Tutorial

All questions for this course