dataTable中筛选数据(datatable.select 和dataview.RowFilter)
Conn.Open();
SqlDataAdapter sda=new SqlDataAdapter(SQL,Conn);
DataSet ds=new DataSet();
sda.Fill(ds,"jing");
ds.WriteXml(path);
DataTable newdt = new DataTable();
DataTable dt;
dt=ds.Tables["jing"];
newdt=dt.Clone();
Label1.Text="1";
Label2.Text="2008/01/04";
System.Data.DataRow[] row=dt.Select("father="+Label1.Text+"and areaID=1");
if(row.Length >0)
{
a=row[0]["areaID"].ToString();
}
//循环添加行
for(int i=0;i<row.Length;i++)
{
newdt.ImportRow((System.Data.DataRow)row[i]);
}
DataGrid1.DataSource=newdt;
DataGrid1.DataBind ();//
DataView dw=new DataView();
dw.Table =ds.Tables ["jing"];
dw.RowFilter="father=1 or father=2";
string temp1="father="+Label1.Text+"and date='"+Label2.Text+"'";
dw.RowFilter=temp1;
DataGrid2.DataSource=dw;
DataGrid2.DataBind ();
转载于:https://www.cnblogs.com/Spirithero/archive/2011/07/20/2111401.html