1

I am working on a project where I am getting values from a series of unknown of database schemas, i.e. the user can enter any database connection details and my program will retrieve the data so I am not going to know the type of tables used and what's stored in them.

At the moment when I try and get the values and store them all in a string so they can be written to a file, but one of the fields I am testing on has a Timestamp value and when I try to store this in the string variable I get the error Unable to convert MySQL date/time value to System.DateTime, I've tried saying .toString() but it doesn't seem to make any difference.

Below is the code I am using to retrieve the data

using (ConnectMySQLDB db = new ConnectMySQLDB(databaseSettings))
{
   string query = string.Format("SELECT * FROM {0}.{1}", database, table);
   using (MySqlCommand cmd = new MySqlCommand(query, db.conn))
   {
      using (MySqlDataReader reader = cmd.ExecuteReader())
      {
         while (reader.Read())
         {
            fieldsAndValues = new Dictionary<string, string>();
            foreach (string field in fields)
            {
               fieldsAndValues.Add(field, reader.GetString(field));

            }
            rows.Add(fieldsAndValues);
         }
      }
   }
}

Thanks for any help you can provide.

Brian
  • 5,069
  • 7
  • 37
  • 47
Boardy
  • 35,417
  • 104
  • 256
  • 447
  • http://stackoverflow.com/questions/2934844/unable-to-convert-mysql-date-time-value-to-system-datetime http://stackoverflow.com/questions/5754822/unable-to-convert-mysql-date-time-value-to-system-datetime – Kashif Apr 11 '13 at 20:02

1 Answers1

0

Unable to convert MySQL date/time value to System.DateTime

Looks like they use different formats for storing time. Hope this solves your issue.

Community
  • 1
  • 1