C# 在DATABLE中应用WROW筛选器时为什么不考虑空值
我已经在数据表中应用了行过滤条件。应用过滤器后,表中不存在空值C# 在DATABLE中应用WROW筛选器时为什么不考虑空值,c#,.net,C#,.net,我已经在数据表中应用了行过滤条件。应用过滤器后,表中不存在空值 为什么不考虑空值,过滤后? 代码示例: " //创建一个包含一列的数据表 DataTable dt=新DataTableMyTable System.Data.DataColumn column = new System.Data.DataColumn("Col", typeof(int)); dt.Columns.Add(column); // Add 5 rows
为什么不考虑空值,过滤后?
代码示例: " //创建一个包含一列的数据表 DataTable dt=新DataTableMyTable System.Data.DataColumn column = new System.Data.DataColumn("Col", typeof(int));
dt.Columns.Add(column);
// Add 5 rows
for (int i = 5; i < 10; i++)
{
System.Data.DataRow row = dt.NewRow();
row["Col"] = i == 5 ? DBNull.Value : row["Col"] = i;
dt.Rows.Add(row);
// Calling AcceptChanges will make the DataRowVersion change from Added to Unchanged in this case
row.AcceptChanges();
}
// Create a DataView
DataView dataView = new DataView(dt);
// Changing the Sort order to descending
dataView.Sort = "Col DESC";
// Filter by an expression.
dataView.RowFilter = "NOT(Col = '6')";
"
请参考所附图片
过滤前
过滤后
在对要筛选的列中可能存在的空记录执行行筛选时,需要执行某种检查或转换,以允许空值返回结果集中。默认情况下,空值被视为未知值,不会返回。下面是一个如何允许空值在过滤器中返回的示例
dataView.RowFilter = "NOT(ISNULL(Col, '') = '6')";
有关详细信息,请参考Microsoft文档网站上的DataView.RowFilter属性文章
要仅返回具有空值的列,请使用以下表达式:
IsnullCol1,'Null Column'='Null Column'
看起来你正在整理桌子。我运行了您的代码,在for循环之后停止,得到一个空行作为第一行,后面跟着6,7,8,9。还有别的事情正在发生。