1

Simple MySQL table containing a single column of type timestamp.

OdbcCommand command = new OdbcCommand("INSERT INTO `mytable` VALUES (?)", DbConnection);
command.Parameters.Add("", OdbcType.Timestamp).Value = DateTime.Now;
OdbcDataReader reader = command.ExecuteReader();

InvalidCastException: Could not convert parameter from DateTime to Byte[]

Error has been translated, but you get the point. How do I insert it correctly?

FYI: I also tried to convert the formatted DateTime string (.ToString(""yyyy-MM-dd HH:mm:ss"")) to a byte array using the function found here. It inserts fine but it results is 0000-00-00 00:00:00.

Community
  • 1
  • 1
jgillich
  • 56,006
  • 5
  • 49
  • 79

1 Answers1

4

Use ObdcType.DateTime instead of OdbcType.Timestamp.

More details on: http://msdn.microsoft.com/en-us/library/yy6y35y8(v=vs.110).aspx

bjnr
  • 3,215
  • 14
  • 26