错误:<目标> .ColumnName和<源> .ColumnName有冲突的属性:DataType属性不匹配属性、不匹配、冲突、错误

由网友(曲未完、词已尽)分享简介:我想合并多个使用DataTable.Merge()选择Excel文件I am trying to merge multiple excel files using DataTable.Merge() optionFor Each fileName As String In Directory.GetFiles("C:...

我想合并多个使用DataTable.Merge()选择Excel文件

I am trying to merge multiple excel files using DataTable.Merge() option

    For Each fileName As String In Directory.GetFiles("C:TEMP.", "*.xls")
        Dim connectionString As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=""Excel 8.0;HDR=NO;IMEX=1;""", fileName)
        Dim adapter As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString)
        Dim ds As New DataSet
        adapter.Fill(ds, "anyNameHere")
        Dim TempTable As DataTable
        TempTable = ds.Tables.Item("anyNameHere")
        table1.Merge(TempTable)
        MsgBox(fileName)
    Next
    DataGridView1.DataSource = table1
    MsgBox(table1.Rows.Count)

但给下面的错误,而合并

But gives following error while merging

<target>.ColumnName and <source>.ColumnName have conflicting properties: DataType property mismatch.

这是由于一个在Excel中列读取文本,另一个作为双,同时都具有数值。

This is due to one column in excel is read as text and another as double while both have numeric values.

要避免这一点,我也提到IMEX = 1在连接字符串,仍然收到此错误。

To avoid this I also mentioned IMEX=1 in connection string, still getting this error.

推荐答案

使用MissingSchemaAction.Ignore在合并MissingSchemaAction参数

Use MissingSchemaAction.Ignore as MissingSchemaAction parameter in Merge

table1.Merge(TempTable, True, MissingSchemaAction.Ignore)
阅读全文

相关推荐

最新文章