如何处理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;