DataTable.Merge in .Net gets an error if there are no columns of interest

Asked 2 years ago, Updated 2 years ago, 94 views

Developed in .Net 4.0 (vb.net).

I'm thinking of using the DataTable.Merge method to combine the two DataTable.

dataTableA.Merge(dataTableB, false, MissingSchemaAction.Error)

If so,

Cannot find definition of column XXX in target table B.

and errors.
Although this may appear to be a simple error, column XXX exists in both dataTableA and dataTableB.

dataTableA.WriteXmlSchema("schemaA.xml")
dataTableB.WriteXmlSchema("schemaB.xml")

The XML of the schema output as also matches.

The error message table name (B) and DataTable.TableName match dataTableB.

dataTableB.Columns.Contains("XXX")

returns True.

Is there anything else you might have overlooked?

There were few similar coding areas, so I decided to use ImportRow in the loop to deal with it.
ImportRow also needs to match the schema, so I don't understand why it works...

.net vb.net

2022-09-30 21:35

1 Answers

var result=dataTableA.AsEnumerable().Union(dataTableB.AsEnumerable()) .CopyToDataTable();

Sorry, I'm not very good at Japanese.


2022-09-30 21:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.