0
DateTime budget_date=new DateTime();

cmd.CommantText="SELECT * FROM dummy";
cmd.Connection=connection
MySqlDataReader=myDataReader=cmd.ExecuteReader();

while(myDataReader.Read())
{
   //gives an error "Unable to convert MySQL date/time value to System.DateTime
   budget_date=Convert.ToDateTime(myDataReader["Budget_Date"]);
}

谁能帮助我如何获取我的变量的日期?

4

1 回答 1

2

检查是否为空。

DateTime? budgetDate;

var ordinal = myDataReader.GetOrdinal("Budget_Date");

var value = myDataReader.GetMySqlDateTime(ordinal);

if(!value.IsValidDateTime && value.IsNull)
{
    budgetDate = null;
}
else if(value.IsValidDateTime)
{
    budgetDate = value.GetDateTime();
}
else
{
    // Error with data
}

看:

于 2013-08-29T17:33:20.727 回答