/// <summary> /// 获取指定表的数据,并转换为jqgrid 的JSON格式。适用于sql2005 以上版本 /// </summary> /// <param name="fields">要选取的列,以逗号隔开</param> /// <param name="pageindex">当前第几页</param> /// <param name="pagesize">每页记录条数</param> /// <param name="order">排序</param> /// <param name="where">条件</param> /// <param name="tbname">表名或视图名</param> /// <returns></returns> public static string GetJsonforjQgrid(string fields, int pageindex, int pagesize, string order, string where, string tbname) { int recordcount = SqlEasy.GetRecordCount(tbname, where); int pagecount = SqlEasy.GetDataPages(pagesize, recordcount); DataTable dt = SqlEasy.GetDataByPager2005(fields, tbname, where, order, pageindex, pagesize); string json = JsonHelper1.DataTableToJSON(dt, "griddata"); string s = "\"totalpages\":\"" + pagecount.ToString() + "\",\"currpage\":\"" + pageindex.ToString() + "\",\"totalrecords\":\"" + recordcount.ToString() + "\","; json = json.Insert(1, s); return(json); }
/// <summary> /// 获取指定表的数据,并转换为jqgrid 的JSON格式。适用于sql2000 以上版本 /// </summary> /// <param name="fields">要选取的列,以逗号隔开</param> /// <param name="pageindex">当前第几页</param> /// <param name="pagesize">每页记录条数</param> /// <param name="orderfield">排序</param> /// <param name="key">关键字</param> /// <param name="where">条件</param> /// <param name="tbname">表名或视图名</param> /// <returns></returns> public static string GetJsonforjQgrid(string fields, int pageindex, int pagesize, string orderfield, string key, string where, string tbname) { int recordcount = 0; DataTable dt = SqlEasy.GetDataByPager2000(fields, tbname, where, orderfield, key, pageindex, pagesize, out recordcount); int pagecount = SqlEasy.GetDataPages(pagesize, recordcount); //string json = DataTableToJSONJquery(dt); string json = JsonConvert.SerializeObject(dt); string s = "{\"totalpages\":\"" + pagecount.ToString() + "\",\"currpage\":\"" + pageindex.ToString() + "\",\"totalrecords\":\"" + recordcount.ToString() + "\",\"griddata\":}"; json = s.Insert(s.Length - 1, json); return(json); }