我有一个DateTime
字段,其值为mysql默认值('0000-00-00 00:00:00')。
我正在使用MySqlDataAdapter
填充DataSet
而不是迭代行并转换行['dateColum']我使用Convert.ToDateTime(object)。
当我将连接字符串设置为Convert Zero Datetime=True
而不是MySqlDataAdapter.Fill获取异常Type of value has a mismatch with column typeCouldn't store <1/1/0001 12:00:00 AM>
但是当我从连接字符串中删除Convert Zero Datetime=True
时,我收到异常Unable to convert MySQL date/time value to System.DateTime
为什么这么简单的事情如此艰难?
编辑:示例
try
{
using (MySqlConnection SQLCon = new MySqlConnection(ConnStrUtils.GetConnectionStr(dbName)))
{
using (MySqlCommand Cmd = new MySqlCommand(query, SQLCon))
{
Cmd.CommandType = CommandType.StoredProcedure;
foreach (var param in parameters)
{
Cmd.Parameters.Add(param);
}
using (MySqlDataAdapter DA = new MySqlDataAdapter(Cmd))
{
DataSet innerDs = new DataSet();
await DA.FillAsync(innerDs);
return innerDs;
}
}
}
}
catch (Exception ex)
{
}
我的连接字符串:datasource=***;port=**;user id=root; password=***; database=indicators; pooling=true; CharSet=utf8; Allow User Variables=True; Convert Zero Datetime=True; Allow Zero Datetime=True; default command timeout=720
1列的db值为0000-00-00 00:00:00
,在fillAsync函数中,我得到:Type of value has a mismatch with column typeCouldn't store <1/1/0001 12:00:00 AM> in p_startTime Column. Expected type is MySqlDateTime.