mysql object(int)类型不匹配_.net c# MySqlDataAdapter错误:值的类型与列类型不匹配

I have this code running on development machine perfectly:

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);

But when I run the same code with same database on the prodcution server it throws this error:

[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

Note: myTimeColumn is datetime in the table.

Same things of the development and production machine:

MySQL server version: 5.6.20

data

.NET Framework version: 4.5.1

MySQL Connector/Net 6.8.3

Different things:

Production OS: Windows Server 2012 R2 (with IIS 8.5)

Development OS: Windows 7 64 bit (with IIS 7.5)

Yes:

I have added Allow Zero Datetime=True and Convert Zero Datetime=True in the connection string.

Thanks for any help,

Solutions1

removing Allow Zero Datetime=True solved the problem.

Solutions2

Removing "Convert Zero Datetime=True" instead Allow Zero Datetime=True is worked for me..... try it

Talk1:

Thx, it works but someone can explain why it works?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值