DataTable常用操作
1.添加列
dt.Columns.Add("A1",typeof(decimal));
2.Select查询
dt.Select("A1 like '%aa%'")
3.排序和分页
//jqgridparam.page 前端传入的页数 jqgridparam.rows 每页行数
DataView dv = dt.DefaultView; dv.Sort = "A1 desc"; DataTable source = dv.ToTable(); DataTable paged = source.Clone(); int rowbegin = (jqgridparam.page-1) * jqgridparam.rows; int rowend = (jqgridparam.page ) * jqgridparam.rows; if (rowend > source.Rows.Count) { rowend = source.Rows.Count; } for (int i = rowbegin; i < rowend; i++) { paged.ImportRow(source.Rows[i]); }
4.修改列名
dt.Columns["Name"].ColumnName = "ShortName";
5.移除列
dt.Columns.Remove("ShortName");