What is the correct way of writing a select statment on c# controller for paging. This is the best I came up with, but I know it doesn’t work because it’s showing all data on my first page on the grid… please help
public JsonResult getData(int start, int limit)
{
List<MyItem> items = new List<MyItem>();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices1"].ConnectionString))
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "SELECT State, Capital FROM MYDBTABLE";
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
MyItem item = new MyItem();
item.State = reader[0].ToString();
item.Capital = reader[1].ToString();
items.Add(item);
}
con.Close();
if ((start + limit) > Myitem.Count)
{
limit = Myitem.Count - start;
}
return Json(new { myTable = items }, JsonRequestBehavior.AllowGet);
}
}
Here’s the template for stored procs that I like to use for paging.
You just need to pass in
page_sizeandpage_numto the stored proc and you’re good to go.