title: Joining Two DataTables -- DataSet does not support System.Nullable<>
body: <p>I'm <code>JOIN</code>ing two DataTales (populated by parsing two Excel spreadsheet).  These Excel spreadsheets contain columns <code>TOTAL_DOLLARS</code> and <code>TOTAL_UNITS</code> that don't always have a value.  Due to this, my program is throwing the following error when I try to run <code>query.CopyToDataTable()</code></p>
  
  <p><code>DataSet does not support System.Nullable&lt;&gt;</code></p>
  
  <pre><code>Dim query = From c In dtDollars.AsEnumerable() _
     Join r In dtUnits.AsEnumerable() _
     On c.Field(Of String)("UPC") Equals r.Field(Of String)("UPC") _
     Select _
     New _
     With {.UPC = r.Field(Of String)("UPC"), .WIC_NUMBER = c.Field(Of String)("WIC_NUMBER"), _
     .WAG_ITEM_DESC = c.Field(Of String)("WAG_ITEM_DESC"), _
     .WAG_BRAND = c.Field(Of String)("WAG_BRAND"), .UOM = c.Field(Of String)("UOM"), _
     .GSK_PROMO_GRP = c.Field(Of String)("GSK_PROMO_GRP"), _
     .TOTAL_DOLLARS = c.Field(Of Decimal?)("TOTAL_DOLLARS"), _
     .TOTAL_UNITS = r.Field(Of Integer?)("TOTAL_UNITS"), _
     .WKND_DATE = c.Field(Of DateTime)("WKND_DATE")}
  
      myResultTable = query.CopyToDataTable()
  </code></pre>
  
  <p>What can I do to resolve this?  Is there a way I can set the default value of these columns to 0 if = <code>DBNull.Value</code>?</p>
  
  <p>Here are the <code>Modules</code> and <code>Extensions</code> I'm using for the <code>CopyToDataTable()</code> method:</p>
  
  <pre><code>Public Module CustomLINQtoDataSetMethods
      &lt;Extension()&gt; _
      Public Function CopyToDataTable(Of T)(ByVal source As IEnumerable(Of T)) As DataTable
          Return New ObjectShredder(Of T)().Shred(source, Nothing, Nothing)
      End Function
  
      &lt;Extension()&gt; _
      Public Function CopyToDataTable(Of T)(ByVal source As IEnumerable(Of T), ByVal table As DataTable, ByVal options As LoadOption?) As DataTable
          Return New ObjectShredder(Of T)().Shred(source, table, options)
      End Function
  
  End Module
  
  Module DataSetLinqOperators
    ''' &lt;summary&gt;
    ''' Creates a &lt;see cref="DataTable"/&gt; that contains the data from a source sequence.
    ''' &lt;/summary&gt;
    ''' &lt;remarks&gt;
    ''' The initial schema of the DataTable is based on schema of the type T. All public property and fields are turned into DataColumns.
    ''' If the source sequence contains a sub-type of T, the table is automatically expanded for any addition public properties or fields.
    ''' &lt;/remarks&gt;
    &lt;Extension()&gt; _
    Public Function ToDataTable(Of T)(ByVal source As IEnumerable(Of T)) As DataTable
      Return New ObjectShredder(Of T)().Shred(source, Nothing, Nothing)
    End Function
  
    ''' &lt;summary&gt;
    ''' Loads the data from a source sequence into an existing &lt;see cref="DataTable"/&gt;.
    ''' &lt;/summary&gt;
    ''' &lt;remarks&gt;
    ''' The schema of &lt;paramref name="table" /&gt; must be consistent with the schema of the type T (all public property and fields are mapped to DataColumns).
    ''' If the source sequence contains a sub-type of T, the table is automatically expanded for any addition public properties or fields.
    ''' &lt;/remarks&gt;
    &lt;Extension()&gt; _
    Public Function LoadSequence(Of T)(ByVal source As IEnumerable(Of T), ByVal table As DataTable, ByVal options As System.Nullable(Of LoadOption)) As DataTable
      If table Is Nothing Then
        Throw New ArgumentNullException("table")
      End If
      Return New ObjectShredder(Of T)().Shred(source, table, options)
    End Function
  End Module
  </code></pre>
  
  <p>Additionally, I'm using the <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;ved=0CDQQFjAA&amp;url=http://msdn.microsoft.com/en-us/library/bb669096.aspx&amp;ei=Kb3UUJnMG8vD0AW90IDQBA&amp;usg=AFQjCNFjeVzDJ4AK5ySDiboe4islrevfdw&amp;sig2=-kTi8jkkv4ecCLtcBzdotQ&amp;bvm=bv.1355534169,d.d2k" rel="nofollow">ObjectShredder</a> class.</p>
  
  <p>Any help is much appreciated!</p>