C# 如何使用 DataTable.Select() 选择 Null/空值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9324088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 06:54:37  来源:igfitidea点击:

how to use DataTable.Select() to select Null/ empty values?

c#.netado.net

提问by haansi

My data table filled from db is having empty values in some cells.

我从 db 填充的数据表在某些单元格中有空值。

The results database SP return has Null in them but in DataTable these values are appearing as '' or empty cells.

结果数据库 SP 返回的结果为 Null,但在 DataTable 中,这些值显示为 '' 或空单元格。

Please guide me how to use Select() to select these dbnull/ empty rows.

请指导我如何使用 Select() 来选择这些 dbnull/空行。

Thanks

谢谢

采纳答案by Thit Lwin Oo

For one column

对于一列

DataRow rows = DataTable.Select("[COLUMN 1]=''");

For more than one column

对于不止一列

DataRow rows = DataTable.Select("[COLUMN 1]='' OR [COLUMN 2]=''");

回答by James McG

The correct way to check for null is to check for it:

检查 null 的正确方法是检查它:

DataRow[] myResultSet = myDataTable.Select("[COLUMN NAME] is null");