Click here to Skip to main content
15,882,830 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i want to insert the button.checked bool but i face problem
this is my code i don't know where is problem?

and this is my error : incorrect integer value :'true' for column 'ThemeColor' at row 1
C#
if (Office2007Blue.Checked == true)
{
    //Blue07();

    try
    {
        _bd = new DataBases();
        _bd.Command.CommandText = " INSERT INTO `Theme`" +
            "(`ThemeColor`) " +
            "VALUES (\"" +
            Office2010Blue.Checked + "\")";
        Debug.WriteLine(Environment.NewLine);
        Debug.WriteLine(_bd.Command.CommandText);
        _bd.Command.ExecuteNonQuery();
    }//try
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(Environment.NewLine);
        System.Diagnostics.Debug.WriteLine(ex.Message);
        MessageBox.Show("Une erreur a été détectée : " + Environment.NewLine + ex.Message, "Erreur");
    }//catch
}//end if
Posted

Your ThemeColor field is obviously an integer type and so it is rejecting a bool value input. If you use a parameterised query, then it should succed. Something like this :

C#
_bd = new DataBases();
_bd.Command.CommandText = "INSERT INTO `Theme` (`ThemeColor`) VALUES (@themecolor)";
_bd.Command.Parameters.AddWithValue("themecolor", Office@010Blue.Checked);

//etc
 
Share this answer
 
thank you Wayne Gaylard
what about update ? i try this but if does not work

C#
try
            {
                //_bd.Command.CommandText = "UPDATE `Theme` " +
                //    "SET ThemeColor = \"" + Office2010Blue.Checked +
                //    "\"";
                _bd.Command.CommandText = "Update `Theme` SET (`ThemeColor`) VALUES   (@themecolor)";
                _bd.Command.Parameters.AddWithValue("themecolor", Office2007Blue.Checked);
                Debug.WriteLine(Environment.NewLine);
                Debug.WriteLine(_bd.Command.CommandText);
                _bd.Command.ExecuteNonQuery();
            }//try
            catch (Exception ex)
            {
                Debug.WriteLine(Environment.NewLine);
                Debug.WriteLine(ex.Message);
                MessageBox.Show("Une erreur a été détectée : " + Environment.NewLine + ex.Message, "Erreur");
            }//catch
 
Share this answer
 
Comments
Naz_Firdouse 8-Jan-14 9:16am    
you need to either remove () at Themecolor or use[]
The update statement should be like thid
C#
_bd.Command.CommandText = "Update `Theme` SET ThemeColor = @themecolor";

 _bd.Command.Parameters.AddWithValue("@themecolor", Office2007Blue.Checked);


refer this for more info
sqlparametercollection.addwithvalue
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900