Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
633 Points
171 Posts
Nov 20, 2010 08:34 AM|LINK
update getdatatable to this . This doesnt take care of paging right now , but we can go to that on next level.
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public s_GridResult GetDataTable(string sidx, string sord, int page, int pagesize) { int startindex = (page - 1) * pagesize; int endindex = page * pagesize; string sql = @" WITH PAGED_CUSTOMERS AS { SELECT BookID,BookName ROW_NUMBER() OVER(ORDER BY " + sidx + @" " + sord + @") AS ROWNUMBER FROM BOOKS}"; DataTable dt = new DataTable(); SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Data Source=.;Initial Catalog=library;Integrated Security=True"].ConnectionString); SqlDataAdapter adapter = new SqlDataAdapter(sql, conn); var rows = adapter.Fill(dt); s_GridResult result = new s_GridResult(); List<s_RowData> rowsadded = new List<s_RowData>(); int idx = 1; foreach (DataRow row in dt.Rows) { s_RowData newrow = new s_RowData(); newrow.id = idx++; newrow.cell = new string[2]; //total number of columns newrow.cell[0] = row[0].ToString(); newrow.cell[1] = row[1].ToString(); rowsadded.Add(newrow); } result.rows = rowsadded.ToArray(); result.page = page; result.total = dt.Rows.Count; result.record = rowsadded.Count; return result; }
Anirudh.Gupt...
Member
633 Points
171 Posts
Re: connect jqgrid to database
Nov 20, 2010 08:34 AM|LINK
update getdatatable to this . This doesnt take care of paging right now , but we can go to that on next level.
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public s_GridResult GetDataTable(string sidx, string sord, int page, int pagesize) { int startindex = (page - 1) * pagesize; int endindex = page * pagesize; string sql = @" WITH PAGED_CUSTOMERS AS { SELECT BookID,BookName ROW_NUMBER() OVER(ORDER BY " + sidx + @" " + sord + @") AS ROWNUMBER FROM BOOKS}"; DataTable dt = new DataTable(); SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Data Source=.;Initial Catalog=library;Integrated Security=True"].ConnectionString); SqlDataAdapter adapter = new SqlDataAdapter(sql, conn); var rows = adapter.Fill(dt); s_GridResult result = new s_GridResult(); List<s_RowData> rowsadded = new List<s_RowData>(); int idx = 1; foreach (DataRow row in dt.Rows) { s_RowData newrow = new s_RowData(); newrow.id = idx++; newrow.cell = new string[2]; //total number of columns newrow.cell[0] = row[0].ToString(); newrow.cell[1] = row[1].ToString(); rowsadded.Add(newrow); } result.rows = rowsadded.ToArray(); result.page = page; result.total = dt.Rows.Count; result.record = rowsadded.Count; return result; }