Select Page
This entry has been published on 2012-06-27 and may be out of date.

Last Updated on 2012-06-27.

This exception is thrown e.g. using the following code in C# .Net 2010:


MySqlCommand cmd = new MySqlCommand("insert into common_history(datetime, username, text) values (@datetime, @username, @text)", adapter.UpdateCommand.Connection);
cmd.Parameters.Add(DateTime.Now);
cmd.Parameters.Add(Environment.UserName);
cmd.Parameters.Add(text);
cmd.BeginExecuteNonQuery();
cmd.Dispose();

Instead, use


MySqlCommand cmd = new MySqlCommand("insert into common_history(datetime, username, text) values (@datetime, @username, @text)", adapter.UpdateCommand.Connection);
cmd.Parameters.AddWithValue("@datetime", DateTime.Now);
cmd.Parameters.AddWithValue("@username",Environment.UserName);
cmd.Parameters.AddWithValue("@text", text);
cmd.BeginExecuteNonQuery();
cmd.Dispose();