我有以下代码来更改颜色并存储到数据库中......出于某种原因,它只允许从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...
我不确定这有什么问题...请指教我谢谢
答案 0 :(得分:0)
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);
}