简体   繁体   English

asp.net-指定的演员表无效Linq

[英]asp.net - Specified cast not valid Linq

I got this error when I am trying the below code 我在尝试以下代码时收到此错误

IEnumerable<DataRow> projjType = from projT in dtProjList.AsEnumerable()
                                 where projT.Field<int?>("ProjectId") == projId && 
                                 projT.Field<int?>("FilterId") == 1 
                                 select projT;

and the stack trace of error is 并且错误的堆栈跟踪是

at System.Data.DataRowExtensions.UnboxT`1.NullableField[TElem](Object value)
   at System.Data.DataRowExtensions.Field[T](DataRow row, String columnName)
   at Folder.Projects.<>c__DisplayClass28.<repProjectList_ItemDataBound>b__1e(DataRow projT) in D:\Folder\Project.aspx.cs:line 1061
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()

where the dtProjList is DataTable,and Table Structure is as follows, 其中dtProjList是DataTable,并且Table Structure如下,

ProjectId (int)
ProjectName (string)
ProjectThumb (string)
FilterTypeId (int)
FilterId (int)
FilterType (string)

all are not null values.Can anybody please help me out. 都不是空值。有人可以帮我吗。

thanks in advance. 提前致谢。

Update :: This is onlyrecord in my table,is the error because of the single record ?? 更新 ::这是我表中的唯一记录,是由于单个记录而导致的错误?

ProjectId   ProjectName ProjectThumb    FilterTypeId    FilterId    FilterType
   1    Datamaster  small_14.jpg         1             1               Final

If all fields are not null, then cast fields to int instead of nullable int? 如果所有字段都不为null,则将字段强制转换为int而不是可为null的int?

var projjType = from projT in dtProjList.AsEnumerable()
                where projT.Field<int>("ProjectId") == projId && 
                      projT.Field<int>("FilterId") == 1 
                select projT;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM