First you need to use DateTime.Parse() to create a .NET DateTime object from a string value, as noted by others.
Resist the temptation to do something like:
var sql = "INSERT INTO MyTable VALUES(" + someDate.ToString() + ")";
It is much better to build a parameterized query, and not just in this case. It also ensures that if you try to insert / update text, you will be able to handle quotes correctly (instead of risking the possibility of sql injection)
using (var conn = new MySqlConnection(connectString)) using (var cmd = new MySqlCommand("INSERT INTO mytable VALUES (1, 2, @theDate)", conn)) { cmd.Parameters.AddWithValue("@theDate", someDate); cmd.ExecuteNonQuery(); }
source share