如何处理DataTable.Select();执行后重新排序的问题!
我使用的方法是用DataView来代替DataTable,详细方法如下:
DateTime dtStart = rule.StartDate;
DateTime dtEnd = rule.EndDate;
// DateTime dtStart = new DateTime(2009,1,1);
// DateTime dtEnd = new DateTime(2009,1,2);
DataTable dtClone = dtReserve.Clone();
DataView dv = dtReserve.DefaultView;
dv.RowFilter = "leave_date >= '" + dtStart.ToString() + "' and leave_date <= '" + dtEnd + "'";
IEnumerator rators = dv.GetEnumerator();
//DataRow[] rows = dtReserve.DefaultView.RowFilter("leave_date >= '" + dtStart.ToString() + "' and leave_date <= '" + dtEnd + "'");
while (rators.MoveNext())
{
object obj = rators.Current;
dtClone.ImportRow(((DataRowView)obj).Row);
}
return dtClone;
DateTime dtEnd = rule.EndDate;
// DateTime dtStart = new DateTime(2009,1,1);
// DateTime dtEnd = new DateTime(2009,1,2);
DataTable dtClone = dtReserve.Clone();
DataView dv = dtReserve.DefaultView;
dv.RowFilter = "leave_date >= '" + dtStart.ToString() + "' and leave_date <= '" + dtEnd + "'";
IEnumerator rators = dv.GetEnumerator();
//DataRow[] rows = dtReserve.DefaultView.RowFilter("leave_date >= '" + dtStart.ToString() + "' and leave_date <= '" + dtEnd + "'");
while (rators.MoveNext())
{
object obj = rators.Current;
dtClone.ImportRow(((DataRowView)obj).Row);
}
return dtClone;
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步