LINQ to XML - handling NULL in SELECT clause

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi there,
Hi, I have the following code, where one element can be NULL.
<pre dir="ltr" style="text-align:left; margin:0px; width:640px; height:146px; border:1px inset; padding:6px Select New Class_Data_Inventory With {.PARTS_AC = CDbl(Data_Inventory.Element("PARTS_AC").Value), _
.PARTS_COMPANY = Data_Inventory.Element("PARTS_COMPANY").Value, _
.PARTS_DIAM = CDbl(Data_Inventory.Element("PARTS_DIAM").Value), _
<span style="color:red .PARTS_LENGTH = CDbl(If(Data_Inventory.Element("PARTS_LENGTH").Value Is Nothing, Data_Inventory.Element("PARTS_LENGTH").Value, "0")), _
.PARTS_NAME = Data_Inventory.Element("PARTS_NAME").Value, _
.PARTS_SD = CDbl(Data_Inventory.Element("PARTS_SD").Value), _
.PARTS_STOCK = Data_Inventory.Element("PARTS_STOCK").Value, _
.PARTS_TYPE = Data_Inventory.Element("PARTS_TYPE").Value}).ToList()[/code]
My question is, how can I handle the NULL value, and assing a 0 to that element, thus avoiding the NULL REFERENCE exception?<br/>
<br/>
So far, no luck!<br/>
<br/>
In the code, I tried the IF clause, but doesnt work at all...<br/>
<br/>
the .PARTS_LENGTH element is defined as DOUBLE and is the value Id like to make 0 if its NULL. <br/>
<br/>
Any help is much appreciated in advance. <hr class="sig Gus

View the full article
 
Back
Top