DateTime value 0000-00-00 00:00:00

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
inTrance
Posts: 10
Joined: Tue 04 Apr 2006 17:07

DateTime value 0000-00-00 00:00:00

Post by inTrance » Fri 14 Apr 2006 15:08

Hello!

How can I read and write the DateTime value "0000-00-00 00:00:00"?
MySQLDirect converts a MySQL-DateTime to a .NET-DateTime so that this
value is lost. I think it's very important to access this value because it is
a common default-value of MySQL.

Kind regards,

Florian Heinemann

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Mon 17 Apr 2006 05:58

To read value "0000-00-00 00:00:00" use code below:

Code: Select all

      mySqlConnection.Open();
      mySqlCommand.CommandText = "select hiredate from Employees";
      MySqlDataReader reader = mySqlCommand.ExecuteReader();
      reader.Read();
      MessageBox.Show(reader.GetString(0));

inTrance
Posts: 10
Joined: Tue 04 Apr 2006 17:07

Post by inTrance » Tue 18 Apr 2006 14:14

Alexey wrote:To read value "0000-00-00 00:00:00" use code below:

Code: Select all

      mySqlConnection.Open();
      mySqlCommand.CommandText = "select hiredate from Employees";
      MySqlDataReader reader = mySqlCommand.ExecuteReader();
      reader.Read();
      MessageBox.Show(reader.GetString(0));
Hello!

Thank you for your reply. Is there any possibility to get the 0-datetime-value through a DataTable? We use the DataAdapter to fill a DataTable, so we cannot choose the data type of the result data as you do it in your example.

And how can we insert the "0000-00-00 00:00:00" value into a mySQL database using parameters?

Kind regards,

Florian Heinemann

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Wed 19 Apr 2006 06:57

To use MySqlDataAdapter you'll have to adjust your query. E.g.:

Code: Select all

select cast(HireDate as char) from Employees
To insert the "0000-00-00 00:00:00" value into a mySQL database use the following code:

Code: Select all

      mySqlConnection.Open();
      mySqlCommand.CommandText = "insert into Employees(EmpNo, HireDate) values(6342, :HireDate)";
      mySqlCommand.Parameters.Add("HireHate", "00/00/0000 00:00:00");
      mySqlCommand.ExecuteNonQuery();

Post Reply