.net 错误:<target>.ColumnName 和 <source>.ColumnName 有冲突的属性:DataType 属性不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/535749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: <target>.ColumnName and <source>.ColumnName have conflicting properties: DataType property mismatch
提问by Sachin Chavan
I am trying to merge multiple excel files using DataTable.Merge() option
我正在尝试使用 DataTable.Merge() 选项合并多个 excel 文件
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.
This is due to one column in excel is read as text and another as double while both have numeric values.
这是因为 excel 中的一列被读取为文本,而另一列被读取为双精度值,而两者都具有数值。
To avoid this I also mentioned IMEX=1 in connection string, still getting this error.
为了避免这种情况,我还在连接字符串中提到了 IMEX=1,但仍然出现此错误。
回答by Sachin Chavan
Use MissingSchemaAction.Ignore as MissingSchemaAction parameter in Merge
在 Merge 中使用 MissingSchemaAction.Ignore 作为 MissingSchemaAction 参数
table1.Merge(TempTable, True, MissingSchemaAction.Ignore)
回答by shahkalpesh
If the columns are numeric, correct the xls file treating that column as text.
Wouldn't you want the columns to be structurally same, when you merge the data?
如果列是数字,请更正将该列视为文本的 xls 文件。
合并数据时,您是否不希望列在结构上相同?

