C# DataTable中使用Select

例子中使用本地XML缓存读取DataSet,从中取出所需DataTable,可在DataTable中选出所需的列以及在Table中做Select 筛选

筛选所需列

 public void BindCob_pnum(DataTable dt)
        {
            if(dt.Rows.Count > 0)
            {
                DataTable dttemp = dt.DefaultView.ToTable(true,new string[] { "Spe_Name" });
                this._cob_pnum.DataSource = dttemp;
                this._cob_pnum.ValueMember = "Spe_Name";
                this._cob_pnum.SelectedIndex = -1;
            }
            else
            {
                this.ShowTips("牌号信息加载失败");
                return;
            }
        }

做Select 筛选

 public void BindCob_stoname(DataTable dt,int dep_id)
        {
            if(dt.Rows.Count > 0)
            {
               DataRow[] rowtemp= dt.Copy().Select(string.Format("Rar_Dep_ID = '{0}'",dep_id));
               DataTable dttemp = rowtemp[0].Table.Clone();
               foreach(DataRow dr in rowtemp)
                {
                    dttemp.ImportRow(dr);
                }
                this._cob_stoname.DataSource = dttemp;
                this._cob_stoname.ValueMember = "Rar_Name";
                this._cob_stoname.SelectedIndex = -1;
            }
            else
            {
                this.ShowTips("货区信息加载失败");
                return;
            }
        }

你可能感兴趣的:(C# DataTable中使用Select)