我完全在开发机器上运行此代码:
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);
但是当我在prodcution服务器上使用相同的数据库运行相同的代码时,它会抛出此错误:
[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是表格中的日期时间。
开发和生产机器的相同事项:
不同的事情:
是:
感谢您的帮助,
答案 0 :(得分:1)
删除Allow Zero Datetime=True
解决了这个问题。
答案 1 :(得分:1)
删除“转换零日期时间=真”而改为允许零日期时间=真为我工作.....试试吧