table merge error

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
 
M

Matt F

There's more than one way to skin a cat. Since I'm not actually merging
here and just adding all records from one datatable to another, I've got a
different route.

Replacing:

tbl.Merge(SourceDataTable, True, MissingSchemaAction.Ignore)

with:

For Each row As DataRow In SourceDataTable.Rows
tbl.ImportRow(row)
Next

Handles things nicely.
 
L

Linda Liu [MSFT]

Hi Matt,

I am curious about your problem : )

I think the problem when you use the Merge method of DataTable may be
caused by the schema of the current DataTable and the DataTable to be
merged.

You may have a try passing False for the second parameter in the Merge
method, something like the following:

tbl.Merge(SourceDataTable, False, MissingSchemaAction.Ignore)

If the problem still exists, could you please send me a sample project that
could reproduce the problem? To get my actual email address, remove
'online' from my displayed email address.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Matt F

Linda,

Replacing the second parameter with "False" doesn't solve the issue. I've
sent email per your request.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top