美文网首页
C# DataTable中使用Select

C# DataTable中使用Select

作者: a9b854aded01 | 来源:发表于2017-11-24 10:24 被阅读0次

    例子中使用本地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

          本文链接:https://www.haomeiwen.com/subject/qrexbxtx.html