Page 1 of 1

Time column in mysql - DateTime datatype in .net?

Posted: Wed 29 Mar 2006 19:11
by shutterstock
How come we can't use GetDateTime for a time column? it has to be a string?

is there any other Get datatype we can use?

if there a reference chart in the docs that maps C# datatypes to mysql datatypes?

thanks!
Jon

Posted: Thu 30 Mar 2006 08:37
by Alexey
If you want to find out which types returns your resultset use MySqlDataAdapter in design time:
1. Place one on the form, right-click it and choose Configure Data Adapter... item from context menu.
2. Type your select query and press Preview... button.
3. In "Preview Data:" window press Schema Tables button and take a look on DataType column.

If you want to have a string representation of data use GetString method of the MySqlDataReader.

If GetDateTime method doesn't work properly please specify the problem.
Hopefully, the following example will be helpful:

Code: Select all

      сonnection.Open();
      MySqlDataReader reader = сommand.ExecuteReader();
      StringBuilder myStr = new StringBuilder("");
      while (reader.Read())
        myStr.Append(reader.GetDateTime(4));
Where 4 - is the number of the column that is of DateTime type in the appropriate table.