简体   繁体   中英

Error with changing color

I have the following code to change colors and store into the database... For some reason it only allows one color to be changed from the colorDialog...

if (colorDialog1.ShowDialog() == DialogResult.OK)
{                
    ColorDialog col = new ColorDialog();
    //col.ShowDialog();
    string color = col.Color.ToArgb().ToString("x");
    color = color.Substring(2, 6);
    color = "#" + color;
    con.Open();
    string sql2 = ("Update Employee SET PanelColor= '" + color + "' WHERE EID='" + 17002 + "' ");
    SqlCommand cmd2 = new SqlCommand(sql2, con);
    SqlDataReader dr2 = cmd2.ExecuteReader();
    con.Close();
    MessageBox.Show(color);
    panel1.BackColor = ColorTranslator.FromHtml(color);
}

Step 1 green color was selected

Step 2 Messagebox showing the color codes(for testing purpose)(wrong color code)

Step 3 it uploads the wrong color into the panel...

I am not sure what is wrong with this... Please advice me thank you

if (colorDialog1.ShowDialog() == DialogResult.OK)
{                

    string color = colorDialog1.Color.ToArgb().ToString("x");
    color = color.Substring(2, 6);
    color = "#" + color;
    con.Open();
    string sql2 = ("Update Employee SET PanelColor= '" + color + "' WHERE EID='" + 17002 + "' ");
    SqlCommand cmd2 = new SqlCommand(sql2, con);
    SqlDataReader dr2 = cmd2.ExecuteReader();
    con.Close();
    MessageBox.Show(color);
    panel1.BackColor = ColorTranslator.FromHtml(color);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM