您的位置:首页 > 其它

如何使用DataTable.Select选出来的Rows生成新的DataTable?

2011-02-26 11:32 267 查看
public DataSet GetPages(string where, int CurrentPageIndex, out int pag)

{

DataSet ds=this.db.ProcPages("select SheetID,SheetNo,(select SheetNo from tProductPlan where SheetID=A.PlanID)as PlanNo,RecordTime,StartTime,FinishTime,TablePerson,SuperPerson,(select DeptName from tDepartment where DeptID=A.DeptID)as DeptName,(select ClassName from tClassDoc where ClassID=A.ClassID)as ClassName,PNO,Status,CheckPerson,CheckDate,TotalMoney,Memo from tSendWorker A where SheetID<>0 " , "SheetID", "SheetID desc", CurrentPageIndex, 15, out pag);

if (where.Trim() != "")

{

DataRow[] dataRows = ds.Tables[0].Select(string.Format("SheetID<>0 {0}", where));

DataTable newTable = ds.Tables[0].Clone();

foreach (DataRow item in dataRows)

{

newTable.Rows.Add(item.ItemArray);

}

ds.Tables.Clear();

ds.Tables.Add(newTable);

}

return ds;

}
http://blog.csdn.net/jing_xin/archive/2010/12/08/6063108.aspx
DataTable dt = 数据源;

DataTable dtt = new DataTable();

dtt=dt.Clone();//拷贝框架,关键点!否则字段都变化了。

DataRow[] dr = dt.select("条件");

for(int i=0;i<dr.length;i++)

{

dtt.ImportRow((DataRow)dr[i]);

}

或者:

//foreach (DataRow row in rows)

//{

//    newdt.Rows.Add(row.ItemArray);

//}

以上两种方式均可以实现由 datarow到datatable


this.DataGrid.DataSource=dtt;
this.DataGrid.DataBind();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: