DataTable通过Select进行过滤
Posted tpf386
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DataTable通过Select进行过滤相关的知识,希望对你有一定的参考价值。
DataTable方法测试
//测试DataTable的select DataTable dt = new DataTable(); //a.OrderType, //a.[Status] dt.Columns.Add("No", typeof(String)); dt.Columns.Add("Type", typeof(String)); dt.Columns.Add("Status", typeof(String)); dt.Rows.Add(new object[] "A01", "N", "N1" ); dt.Rows.Add(new object[] "A01", "G", "G1" ); dt.Rows.Add(new object[] "A01", "T", "T1" ); dt.Rows.Add(new object[] "A01", "N", "N2" ); dt.Rows.Add(new object[] "A02", "G", "G1" ); dt.Rows.Add(new object[] "A02", "T", "T1" ); dt.Rows.Add(new object[] "A03", "N", "N1" ); dt.Rows.Add(new object[] "A04", "S", "S1" ); dt.Rows.Add(new object[] "A05", "G", "G1" ); dt.Rows.Add(new object[] "A05", "T", "T1" ); DataRow[] arrRow = dt.Select("No=‘A01‘ and ((Type=‘N‘) or (Type=‘G‘ and Status<>‘G1‘) or(Type=‘T‘ and Status<>‘T1‘))"); //Console.WriteLine(arrRow[0]["Type"]); var arrRow2= arrRow.Select<DataRow,DataRow>(dr=> if (dr["Type"].ToString() == "N") return dr; else return null; ); foreach(var r in arrRow2) if(r!=null) Console.WriteLine(r["No"].ToString()+"===="+r["Status"].ToString());
以上是关于DataTable通过Select进行过滤的主要内容,如果未能解决你的问题,请参考以下文章
C在一个DataTable中,Select方法如何写筛选条件达到过滤出数值型空的值?