I want to insert an Enum value using the parameter collection of the MySqlCommand. Sadly this results in an MySqlException telling me this:
Creating the query manually is working."Unknown column 'Done' in 'field list'"
The query is than looking like:
Code: Select all
REPLACE INTO result (ErrorMessage,Status,Identification) VALUES ('test','Done', UUID());
Code: Select all
public enum Status { Error, Done};
class Program
{
static void Main(string[] args)
{
MySqlCommand cmd = new MySqlCommand()
{
CommandText = "REPLACE INTO result (ErrorMessage,Status,Identification) VALUES ('test',:Status, UUID());"
};
cmd.Parameters.Add("Status", Status.Done);
using (MySqlConnection connection =
new MySqlConnection()
{
Host = "localhost",
UserId = "root",
Password = "xxx",
Database = "test"
})
{
connection.Open();
cmd.Connection = connection;
cmd.ExecuteNonQuery();
}
}
}
Code: Select all
CREATE TABLE `test`.`result` (
`Identification` varchar(36) NOT NULL,
`Status` enum('Error','Done') NOT NULL,
`ErrorMessage` text NOT NULL,
PRIMARY KEY USING BTREE (`Identification`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;