C# DataTable.Select() - 如何格式化过滤条件以包含空值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16767010/
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
C# DataTable.Select() - How do I format the filter criteria to include null?
提问by Arun Chandran C
This doesn't work
这不起作用
DataTable myNewTable = myDataTable.Select("Name <> 'n/a'").CopyToDataTable();
myDataTablehas a row named Name. I would like to select the rows from this table where Name is not equal to "n/a". It selects but still am missing the null values i need the null values too.
myDataTable有一行名为Name. 我想从此表中选择 Name 不等于“n/a”的行。它选择但仍然缺少空值,我也需要空值。
Can anyone help?
任何人都可以帮忙吗?
采纳答案by Rajeev Kumar
Try this
尝试这个
myDataTable.Select("[Name] is NULL OR [Name] <> 'n/a'" )
Edit: Relevant sources:
编辑:相关来源:
回答by Freelancer
Try out Following:
尝试以下:
DataRow rows = DataTable.Select("[Name]<>'n/a'")
For Null check in This:
对于空值检查:
DataRow rows = DataTable.Select("[Name] <> 'n/a' OR [Name] is NULL" )
回答by ????
The way to check for null is to check for it:
检查 null 的方法是检查它:
DataRow[] myResultSet = myDataTable.Select("[COLUMN NAME] is null");
You can use andand orin the Selectstatement.
您可以在语句中使用and和。orSelect
回答by SeeSharp
try this:
尝试这个:
var result = from r in myDataTable.AsEnumerable()
where r.Field<string>("Name") != "n/a" &&
r.Field<string>("Name") != "" select r;
DataTable dtResult = result.CopyToDataTable();

