How do I check for blank in DataView.RowFilter

江枫思渺然 提交于 2019-12-05 04:29:41
Will Charczuk

Are you tied to .net < 3.5? If not you can use linq to check the state of a column.

Otherwise there is an Isnull(,) function like in T-SQL:

dv.RowFilter = "Isnull(a,'') <> ''";

I am assuming you need to retrieve all the records where the value in column A is neither null nor ''

The correct expr is:

 dv.RowFilter = "A IS NOT NULL AND A <> ''";

And to retrieve the filtered records loop on dv.ToTable() like this:

foreach (DataRow dr in dv.ToTable().Rows)
    Console.WriteLine(dr["A"]);

This should work ... cheers!!

You can add

dv.RowFilter = "CONVERT(Isnull(a,''), System.String) <> ''"

if a column has data type of number as Isnull(a,'') would return number. Eval of number <> 0 would throw the exception.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!