datatable.select 和dataview.RowFilter

原文链接:http://www.cnblogs.com/Spirithero/archive/2011/07/20/2111401.html

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

上一篇:DataView.RowFilter 注意事项


下一篇:Traefik 2.0 实现灰度发布