日期:2014-05-17  浏览次数:20951 次

DataTable如何去掉值全为NULL或者空的列
A  B  C
1     3
2     0
3     

例如上面的DataTable,删除列B。有没有简单的方法~
DataTable

------解决方案--------------------
select A,B from table1
------解决方案--------------------

for(int i = t.Columns.Count - 1 ; i >= 0 ; i --)
{
    foreach(DataRow r in t.Rows)
    {
        if(!r.IsNull(t.Columns[i]))
          continue;
    }
    t.Columns.RemoveAt(i);
}