M
Matt F
I'm having difficulty with a function and can't find what the problem is.
The code is below. Essentially, it works fine if the target table (tbl
variable in code) is empty, however if it contains rows prior to the method
being called, the error "'column' argument cannot be null" is thrown on the
tbl.merge line. Any help would be greatly appreciated.
''' <summary>Imports data from the table passed in.</summary>
''' <returns>Number of successfully imported rows. Returns 0 for
error.</returns>
Public Function AppendDataTable(ByVal SourceDataTable As DataTable) As
Int32
If SourceDataTable Is Nothing Then
Return 0
End If
Try
Dim ds As DataSet = DirectCast(mBindingSource.DataSource, DataSet)
Dim tbl As DataTable = ds.Tables(mBindingSource.DataMember)
tbl.Merge(SourceDataTable, True, MissingSchemaAction.Ignore) '
error is thrown by this line
' some other stuff happens here specific to my code, but removed
for simplicity
Return SourceDataTable.Rows.Count
Catch ex As Exception
Return 0
End Try
End Function
The code is below. Essentially, it works fine if the target table (tbl
variable in code) is empty, however if it contains rows prior to the method
being called, the error "'column' argument cannot be null" is thrown on the
tbl.merge line. Any help would be greatly appreciated.
''' <summary>Imports data from the table passed in.</summary>
''' <returns>Number of successfully imported rows. Returns 0 for
error.</returns>
Public Function AppendDataTable(ByVal SourceDataTable As DataTable) As
Int32
If SourceDataTable Is Nothing Then
Return 0
End If
Try
Dim ds As DataSet = DirectCast(mBindingSource.DataSource, DataSet)
Dim tbl As DataTable = ds.Tables(mBindingSource.DataMember)
tbl.Merge(SourceDataTable, True, MissingSchemaAction.Ignore) '
error is thrown by this line
' some other stuff happens here specific to my code, but removed
for simplicity
Return SourceDataTable.Rows.Count
Catch ex As Exception
Return 0
End Try
End Function