对Dataset 进行查询的几中方法。

来源:互联网 发布:linux shell遍历文件夹 编辑:程序博客网 时间:2024/05/29 09:03

1. 查询的数据用dataview 显示

 

  DataRow[] drStock = dsStockInfo.Tables[0].Select("");
    DataTable dtStock =dsStockInfo.Tables[0].Clone();
   //提取数据一行一列的添加到视图中在grdOrderDetail中显示
   for(int i=0; i<drStock.Length;i++)
   {
    DataRow drr= dtStock.NewRow();
    for(int j=0;j<dtStock.Columns.Count;j++)
    {
     drr[j] = drStock[i][j];
    }
    dtStock.Rows.Add(drr);
   }
   dvStock   =   new   DataView(dtStock);

 

 

2. 把数据集从一个导入到另一个

m_dataSetNew=dsSupplyInfo.Clone();

 m_dataSetNew.Tables[0].Clear();
    dsSupplyInfo.Tables[0].DefaultView.RowFilter = "Expr2="+PickLine+" and CLASSNAME= '" +ProductType +"' and CLIENTCODE= " +orderNo +" ";
    dsSupplyInfo.Tables[0].DefaultView.AllowNew = false;
    //提取数据一行一列的添加到视图中在grdOrderDetail中显示
    for(int i=0; i<dsSupplyInfo.Tables[0].DefaultView.Count;i++)
    {
     m_dataSetNew.Tables[0].ImportRow(dsSupplyInfo.Tables[0].DefaultView[i].Row);
    }
    
    this.hkdgSupply.DataSource   =   m_dataSetNew.Tables[0];

 

3. 过滤只是一个显示

   dsStockInfo.Tables[0].DefaultView.RowFilter = "PICKLINE="+PickLine+" and CLASSNAME= '" +ProductType +"' and ORDERID= " +orderNo +" ";
    dsStockInfo.Tables[0].DefaultView.AllowNew = false;
    //提取数据一行一列的添加到视图中在grdOrderDetail中显示
    this.hkdgStock.DataSource=dsStockInfo.Tables[0].DefaultView;