我有这样的查询。
DataTable products = ...
redirect_str = ...
IEnumerable<DataRow> productsQuery =
from product in products.AsEnumerable()
where product.Field<String>("url") == redirect_str
select product;
它工作正常。
但是我如何在不考虑大小写的情况下比较 product.Field("url") 和 redirect_str .我试过了,但没用。
IEnumerable<DataRow> productsQuery =
from product in products.AsEnumerable()
where product.Field<String>("url").ToUpper() == redirect_str.ToUpper()
select product;
最佳答案
你没有说“不起作用”是什么意思,但你可以尝试:
...
where String.Equals(product.Field<String>("url"),
redirect_str,
StringComparison.OrdinalIgnoreCase)
...
即使其中一个值为 null,这也会起作用 (*),而您使用 ToUpper()
会抛出 NullReferenceException
。
(*) 如果您想要进行不区分文化的序数比较,请使用“work”。如果不是,请为 StringComparison 参数使用不同的值。
关于c# - DataTable Linq where 子句与大写比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22047884/