【发布时间】:2014-11-10 19:47:03
【问题描述】:
我已经在开发机器上完美运行了这段代码:
MySqlCommand cmd = new MySqlCommand("select * from orders where id=1", conn);
System.Data.DataTable dt = new System.Data.DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dt);
但是当我在生产服务器上使用相同的数据库运行相同的代码时,它会抛出此错误:
[ArgumentException: Type of value has a mismatch with column type]
System.Data.Common.ObjectStorage.Set(Int32 recordNo, Object value) +2256750
System.Data.DataColumn.set_Item(Int32 record, Object value) +60
[ArgumentException: Type of value has a mismatch with column typeCouldn't store <1.1.0001 00:00:00> in myTimeColumn Column. Expected type is MySqlDateTime.]
System.Data.DataColumn.set_Item(Int32 record, Object value) +6632812
System.Data.DataTable.NewRecordFromArray(Object[] value) +6638777
System.Data.DataTable.LoadDataRow(Object[] values, Boolean fAcceptChanges) +111
System.Data.ProviderBase.SchemaMapping.LoadDataRow() +148
System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping) +141
System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) +292
System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) +657
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +368
System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +487
System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +293
注意:myTimeColumn 是表中的日期时间。
开发和生产机器的东西:
- MySQL 服务器版本:5.6.20
- 数据
- .NET Framework 版本:4.5.1
- MySQL 连接器/网络 6.8.3
不同的东西:
- 生产操作系统:Windows Server 2012 R2(带有 IIS 8.5)
- 开发操作系统:Windows 7 64 位(带 IIS 7.5)
是的:
- 我在连接字符串中添加了 Allow Zero Datetime=True 和 Convert Zero Datetime=True。
感谢您的帮助,
【问题讨论】:
标签: c# mysql dataadapter