I have a generic method that lets me run a query inside scheduled Tasks like this:
public static DataSet ExecuteQuery(string strQuery)
{
DataSet ds = new DataSet();
using (MySqlConnection mySqlConnection = new MySqlConnection("server=localhost;uid=root;database=sampleDB"))
{
mySqlConnection.Open();
using (MySqlDataAdapter dataAdapter = new MySqlDataAdapter(strQuery, mySqlConnection))
{
dataAdapter.TableMappings.Add("Table", "data");
dataAdapter.Fill(ds);
}
mySqlConnection.Close();
}
return ds;
}
To use this, I can call it from inside my task like this:
DataSet results = DataConnection.ExecuteQuery("SELECT * from appointments");
I have been looking for a way to paginate results, but every solution I could find uses a DataGrid and buttons to navigate from page to page.
I tried using the extension from this page: LINQ and pagination, but it seems to need to be further downstream after results have been added to a List, at which point the Mysql query would have already been executed and returned potentially hundreds of thousands of results to be stored in memory.
I would like to still have this end up with the same simple call, but change it up to something like:
DataSet results = DataConnection.ExecuteQuery("SELECT * from appointments", 1, 50);