I have a DbCommand created as such.
DbCommand cmd = conn.CreateCommand();
I then create cmd.CommandText of the format.
"Insert into myTable (`Id`,`myDate`) values (@p0,@p1)"
When dealing with the second parameter (after creating the first) I have code of the form.
var p2 = command.CreateParameter();
p2.ParameterName = "@p2";
p2.Value = myDateTimeObject; //not a string but an actual DateTime object
command.Parameters.Add(p2);
In my code I have the following section to execute DbCommand variables.
int result = cmd.ExecuteNonQuery();
When I actually execute this, it successfully creates the following statement but this statement errors when MySQL tries to execute it.
Insert into myTable (`Id`,`myDate`) values (1,'27/08/2018 16:50:30')
And when I look at the error it is the following.
Error Code: 1292. Incorrect datetime value: '27/08/2018 16:50:30' for column 'myDate' at row 1 0.000 sec
Is there anything I can do to ensure it runs with valid SQL that MySQL will accept? I'm happy to provide more information if necessary.