如何过滤数据表 [英] How to Filter Data Table

查看:86
本文介绍了如何过滤数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表,其中包含ID 1,2,3,5,8和文本'A','X','T'等等

我想过滤数据表以这种方式它应该删除ID 2,5

I have a Data Table, which contain ID 1,2,3,5,8 & Text 'A','X','T' so on
I want to filter Data Table in such a way that it should remove where ID 2,5

推荐答案

从数据表使用数据列尝试这个并比较值并复制除你想要的值之外的值删除

try this from data table use data column and compare values and copy the values except those you want to remove
 DataTable DataTablecase = new DataTable("count");
 da4.Fill(DataTablecase);
 DataColumn dc6 = DataTablecase.Columns[0];
 DataColumn dc7 = DataTablecase.Columns[1];
 if (DataTablecase.Rows.Count > 0)
 {
   foreach (DataRow row1 in DataTablecase.Rows)
   {
     if((Convert.ToInt32(row1[dc6])!=2)||(Convert.ToInt32(row1[dc6])!=5))
     {
        //declare the array and i
        a[i]=Convert.ToInt32(row1[dc6]);
        b[i]=(row1[dc7].ToString())
        i++;
     }
   }
}


这篇关于如何过滤数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆