User-1697400506 posted
I am using MySQL version 5. In one of my methods and got an exception when fill the dataset:
Table definition:
RevisionRequestID VARCHAR(36)
RequestDate DATE
RequestTime TIME
RequestBy VARCHAR(50)
Generated ENUM('F','T')
Revision INT(11)
GenerateDate DATE
GenerateTime TIME
protected DataSet ExecuteDataSet(string query)
{
MySqlConnection connection;
MySqlCommand cmd;
MySqlDataAdapter da;
connection = null;
cmd = null;
DataSet ds = new DataSet();
da = new MySqlDataAdapter();
try
{
//cmd = new MySqlCommand(query);
cmd = new MySqlCommand(
" SELECT " +
" RevisionRequestID, RequestDate, " +
" RequestBy, Generated, Revision, GenerateDate " +
"FROM elogrevisionrequest ");
cmd.CommandType = CommandType.Text;
da.SelectCommand = (MySqlCommand)cmd;
connection = new MySqlConnection(GetConnectionString());
cmd.Connection = connection;
connection.Open();
// fill the dataset
da.Fill(ds);
}
catch
{
throw;
}
finally
{
if (da != null)
da.Dispose();
if (cmd != null)
cmd.Dispose();
// implicitly calls close()
connection.Dispose();
}
return ds;
}
I got an exception in the statement:
da.Fill(ds);
It was working but suddenly stop working. So I now use the hard-coded SQL to run the data set return:
"SELECT " +
" RevisionRequestID, RequestDate, " +
" RequestBy, Generated, Revision, GenerateDate " +
" FROM elogrevisionrequest"
RequestDate and GenerateDate are Date type in MySQL.
If I took away the field GenerateDate from SELECT, it's fine.
The exception message was:
"Unable to convert MySQL date/time value to System.DateTime"
Any idea?