Linq 多条件查询DATATABLE数据时,报Linq Exception(NullReferenceException)错误
来源:互联网 发布:如何申请淘宝图片保护 编辑:程序博客网 时间:2024/06/05 23:46
Linq 代码中where下有多个条件,执行时报此错误:
Linq Exception(NullReferenceException): Object reference not set to an instance of an object
With NullReferenceException:
GOOGLE后得到解决方案如下:
old code -->
Dim obj As DemographicProperties = Me
Dim m As IEnumerable(Of DemographicProperty) = From c In obj _
Where (c.MapClass.MapClassID = MapClassID) _
Order By c.Name Ascending _
Select c
new code -->
If you are getting NullReferenceException, it means the MapClassID is null(nothing in vb.net)
Solve:
Dim obj As DemographicProperties = Me
Dim m As IEnumerable(Of DemographicProperty) = From c In obj _
Where ((Not c.MapClass Is Nothing) AndAlso (c.MapClass.MapClassID = MapClassID)) _
Order By c.Name Ascending _
Select c
reference:
http://scripting.chaindb.com/2010/09/24/linq-exceptionnullreferenceexception-object-reference-not-set-to-an-instance-of-an-object/
- Linq 多条件查询DATATABLE数据时,报Linq Exception(NullReferenceException)错误
- Linq多条件查询
- LINQ多条件查询
- linq动态多条件查询
- Linq 无限制多条件查询
- linq中的多条件查询
- Datatable中linq查询
- datatable筛选、查询-------linq
- datatable linq查询
- LINQ 多条件查询 where 条件组建
- Linq动态条件查询
- Linq条件累加查询
- Linq的条件查询
- Linq查询(多条件join on查询)
- Linq 的多条件组合查询
- linq to sql 多条件组合查询
- linq 多条件组织查询核心代码
- Linq 多条件查询组合问题
- 消息和消息队列(Using Messages and Message Queues)
- android 源码下载及编译
- Bigdecimal的简单应用
- android开发我的新浪微博客户端-OAuth认证过程中用WebView代替原来的系统自带浏览器
- C++程序设计实验报告《二》
- Linq 多条件查询DATATABLE数据时,报Linq Exception(NullReferenceException)错误
- error: macro "min" passed 3 arguments, but takes just 2 error: expected ‘)’ before ‘const’ 解决方法
- 第四周任务(四)
- 查找最小的k个元素(数组)
- Html5 Canvas初探学习笔记(2) -绘制深入
- VC 多线程编程
- JAVA方法重载和方法重写
- lua <--> c++
- 第五周任务(一)