使用Linq连接两个数据集并获取System.Data.StrongTypingException [英] Using Linq to joint two datasets and getting System.Data.StrongTypingException

查看:109
本文介绍了使用Linq连接两个数据集并获取System.Data.StrongTypingException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据集中的两个表连接在一起并收到消息:

System.Data.StrongTypingException未处理
消息="列的值表'Part_Descriptions'中的'Component_ID'是DBNull。"

我一直在通过论坛查看我做错了什么,但没有提出任何想法?


  Dim  dataTable = _ 
来自PartUsedRow Ds_Database.Service_Call_Parts_Used.DefaultIfEmpty _
加入DescriptionRow Ds_Database.Part_Descriptions.DefaultIfEmpty _
PartUsedRow.Part_Number等于DescriptionRow.Part_Number _
选择 PartUsedRow.Prob_7,PartUsedRow.Part_Number,DescriptionRow.Component_ID,DescriptionRow.Element_ID, _
DescriptionRow.SkillSet_ID

解决方案

你不能在值为DBNULL的情况下进行INNER JOIN,但你可以进行左外连接。

在这种特殊情况下,我会使用LINQ连接两个DataTables,其中vaue不是DBNULL,或者可能再次向数据库写一个小查询。

I am trying to join two tables from a datasete together and am getting the message:

System.Data.StrongTypingException was unhandled
  Message="The value for column 'Component_ID' in table 'Part_Descriptions' is DBNull."

I have been looking through the forums for a hint to what I am doing wrong, but have come up with nothing... any ideas?

Dim dataTable = _
        From PartUsedRow In Ds_Database.Service_Call_Parts_Used.DefaultIfEmpty _
        Join DescriptionRow In Ds_Database.Part_Descriptions.DefaultIfEmpty _
        On PartUsedRow.Part_Number Equals DescriptionRow.Part_Number _
        Select PartUsedRow.Prob_7, PartUsedRow.Part_Number, DescriptionRow.Component_ID, DescriptionRow.Element_ID, _
               DescriptionRow.SkillSet_ID

解决方案

You can't do an INNER JOIN where a value is DBNULL, but you can do a LEFT OUTER JOIN.

In this particular case, I would use LINQ to join the two DataTables where the vaue isnot DBNULL or perhaps write a small query into the database again.


这篇关于使用Linq连接两个数据集并获取System.Data.StrongTypingException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆