如何从列表中的列中选择 Nullable 值。
例如,我将一个数据集转换为如下所示的列表,而不是在客户端 ID(可空列)中传递一个值。我需要传递空值。我自己做了以下尝试:
var reqlist = (from list in tableList.AsEnumerable()
where (list.Field<int?>("ClientID") == clientID)
&& list.Field<bool>("VisibleToAdmin") == true
&& list.Field<bool>("Required") == true
select list.Field<string>("FieldName"));
1.
var reqlist = (from list in tableList.AsEnumerable()
where (list.Field<int?>("ClientID") == null)
&& list.Field<bool>("VisibleToAdmin") == true
&& list.Field<bool>("Required") == true
select list.Field<string>("FieldName"));
2.
var reqlist = (from list in tableList.AsEnumerable()
where (list.Field<int?>("ClientID") == (int?)(null))
&& list.Field<bool>("VisibleToAdmin") == true
&& list.Field<bool>("Required") == true
select list.Field<string>("FieldName"));
3.
var reqlist = (from list in tableList.AsEnumerable()
where (list.Field<int?>("ClientID") == (bool?)(null))
&& list.Field<bool>("VisibleToAdmin") == true
&& list.Field<bool>("Required") == true
select list.Field<string>("FieldName"));
4.
var reqlist = (from list in tableList.AsEnumerable()
where (list.IsNull("ClientID"))
&& list.Field<bool>("VisibleToAdmin") == true
&& list.Field<bool>("Required") == true
select list.Field<string>("FieldName"));
使用上述所有方法,InvalidCastException
都会抛出 an 。