Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 连接两个数据表--数据集不支持System.Nullable<&燃气轮机;_Vb.net_Linq_Datatable_Dataset_Extension Methods - Fatal编程技术网

Vb.net 连接两个数据表--数据集不支持System.Nullable<&燃气轮机;

Vb.net 连接两个数据表--数据集不支持System.Nullable<&燃气轮机;,vb.net,linq,datatable,dataset,extension-methods,Vb.net,Linq,Datatable,Dataset,Extension Methods,我正在加入两个数据故事(通过解析两个Excel电子表格填充)。这些Excel电子表格包含不总是有值的列TOTAL_DOLLARS和TOTAL_UNITS。因此,当我尝试运行query.CopyToDataTable() 数据集不支持System.Nullable 我能做些什么来解决这个问题?如果=DBNull.value,有没有办法将这些列的默认值设置为0 以下是我用于CopyToDataTable()方法的模块和扩展: Public Module CustomLINQtoDataSetMeth

我正在加入两个数据故事(通过解析两个Excel电子表格填充)。这些Excel电子表格包含不总是有值的列
TOTAL_DOLLARS
TOTAL_UNITS
。因此,当我尝试运行
query.CopyToDataTable()

数据集不支持System.Nullable

我能做些什么来解决这个问题?如果=
DBNull.value
,有没有办法将这些列的默认值设置为0

以下是我用于
CopyToDataTable()
方法的
模块
扩展

Public Module CustomLINQtoDataSetMethods
    <Extension()> _
    Public Function CopyToDataTable(Of T)(ByVal source As IEnumerable(Of T)) As DataTable
        Return New ObjectShredder(Of T)().Shred(source, Nothing, Nothing)
    End Function

    <Extension()> _
    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
  ''' <summary>
  ''' Creates a <see cref="DataTable"/> that contains the data from a source sequence.
  ''' </summary>
  ''' <remarks>
  ''' 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.
  ''' </remarks>
  <Extension()> _
  Public Function ToDataTable(Of T)(ByVal source As IEnumerable(Of T)) As DataTable
    Return New ObjectShredder(Of T)().Shred(source, Nothing, Nothing)
  End Function

  ''' <summary>
  ''' Loads the data from a source sequence into an existing <see cref="DataTable"/>.
  ''' </summary>
  ''' <remarks>
  ''' The schema of <paramref name="table" /> 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.
  ''' </remarks>
  <Extension()> _
  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
公共模块CustomLINQtoDataSetMethods
_
公共函数CopyToDataTable(Of T)(ByVal源作为IEnumerable(Of T))作为DataTable
返回新的ObjectShreder(Of T)().Shred(源,无,无)
端函数
_
公共函数CopyToDataTable(Of T)(ByVal源作为IEnumerable(Of T),ByVal表作为DataTable,ByVal选项作为LoadOption?)作为DataTable
返回新的ObjectShreder(Of T)().Shred(源、表、选项)
端函数
端模块
模块数据采集器
''' 
''创建包含来自源序列的数据的。
''' 
''' 
''DataTable的初始架构基于T类型的架构。所有公共属性和字段都转换为DataColumns。
''如果源序列包含T的子类型,则该表将自动展开以添加任何公共属性或字段。
''' 
_
公共函数ToDataTable(Of T)(ByVal源作为IEnumerable(Of T))作为DataTable
返回新的ObjectShreder(Of T)().Shred(源,无,无)
端函数
''' 
''将数据从源序列加载到现有序列中。
''' 
''' 
''的架构必须与T类型的架构一致(所有公共属性和字段都映射到DataColumns)。
''如果源序列包含T的子类型,则该表将自动展开以添加任何公共属性或字段。
''' 
_
公共函数LoadSequence(Of T)(ByVal源作为IEnumerable(Of T),ByVal表作为DataTable,ByVal选项作为System.Nullable(Of LoadOption))作为DataTable
如果这张桌子什么都不是
抛出新ArgumentNullException(“表”)
如果结束
返回新的ObjectShreder(Of T)().Shred(源、表、选项)
端函数
端模块
另外,我正在使用这个类

非常感谢您的帮助

试试这个:

.TOTAL_DOLLARS = If( (c.Field(Of Decimal?)("TOTAL_DOLLARS")).HasValue, _
                     (c.Field(Of Decimal?)("TOTAL_DOLLARS"), 0))
这有点尴尬,但应该可以用。

试试这个:

.TOTAL_DOLLARS = If( (c.Field(Of Decimal?)("TOTAL_DOLLARS")).HasValue, _
                     (c.Field(Of Decimal?)("TOTAL_DOLLARS"), 0))

这有点尴尬,但应该能用。

奇怪。当我运行
query.CopyToDataTable()
时,程序仍返回
数据集不支持System.Nullable
。最初,VisualStudio抱怨缺少右括号。也许是我错误地修正了语法错误?奇怪。当我运行
query.CopyToDataTable()
时,程序仍返回
数据集不支持System.Nullable
。最初,VisualStudio抱怨缺少右括号。也许我修正了语法错误?