ASP.NET 2.0/c#: Passing decimal as parameter in parameterized sql query using MySql
Posted on 2006-07-20
I am working on a web application in ASP.NET 2.0.
I have a webform, on which users can input data in textboxes, which is then send to the MySql database by a parameterized query.
The problem is, if I use decimals, then somehow the query just get mangled and doesn't execute.
This is probably because the decimal has a comma seperator, which wrecks the insert query.
dec NoOfHours = Convert.ToDecimal(txtNoOfHours.Text);
MySqlCommand updCommand = new MySqlCommand();
updCommand.Connection = myConnection;
updCommand.CommandText = "INSERT INTO items (NoOfHours) VALUES (?NoOfHours)"
updCommand.Parameters.Add(new MySqlParameter("?NoOfHours", NoOfHours));
updCommand.ExecuteNonQuery(); //it breaks here, giving me a wrong sql syntax error.
Anyone able to help me out here?