2009-02-26 51 views
0

我想统计一个Datatable中每列的非空值数。我可以遍历列并在每列上使用计算函数,但我想知道是否有更高效的方法来实现这一点。多列的数据表计算功能

回答

1

我认为在这种情况下Compute函数是非常合适的。你可以使用类似下面的代码:

For Each col as DataColumn in myTable 
    Dim aggExpr as string = string.format("Count{0}", col.ColumnName) 
    Dim filterExpr as string = string.format("{0} IS NULL", col.ColumnName) 
    Dim myCount as integer = CInt(myTable.Compute(aggExpr, filterExpr)) 
    Console.WriteLine(myCount) 
Next 

(在这里打字,看语法)

请注意,我说:“类似于以下”。请添加适当的错误/空值检查。

+0

谢谢,但这是我们已经在做的事情。我正在寻找不需要遍历所有列的内容 – 2009-02-26 09:54:22