Page 1 of 1
DateTime value 0000-00-00 00:00:00
Posted: Fri 14 Apr 2006 15:08
by inTrance
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
Posted: Mon 17 Apr 2006 05:58
by Alexey
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));
Posted: Tue 18 Apr 2006 14:14
by inTrance
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
Posted: Wed 19 Apr 2006 06:57
by Alexey
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();