I'm trying to update a table element of type timestamp called dtprint with the current time (the original value is NULL). The code that I am using is as follows:
MySqlConnection con = new MySqlConnection("Connection_String");
con.Open();
MySqlCommand _cmd = con.CreateCommand();
string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
_cmd.CommandText = "UPDATE requests SET dtprint = " + dt + " WHERE idPerson = " + _personID[index];
_cmd.ExecuteNonQuery();
con.Close();
The exception I keep getting is: Additional information: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '14:03:23 WHERE idPerson = 45' at line 1.
The only thing I can think of is that the Database isn't recognizing the time as a timestamp, any help is greatly appreciated.
dtprintandidPersoncolumns? And you should always use parameterized queries. This kind of string concatenations are open for SQL Injection attacks. If yourdtprintis atimestamp, you should add it aDateTime, notstring.'" + dt + "'_cmd.ExecuteNonQuery();around a try{}catch(SqlException sqlEx{show the sqlEx.Message here} so that you can capture the SQLException