Net Eth

Net Eth

  • NA
  • 1
  • 1.8k

How to insert background color from a variable

Jan 16 2013 5:48 AM
Hello:
I am working in visual studio (C#) and i wanted to fill the back groud color of my forms to be filled from a variable which is stored in a database. the datatype of the variable is nvarchar. i wrote the following code but it does't seem to work
string connString = "Server=.\\SQLExpress;Database=MyDB;Trusted_Connection=Yes;";
  SqlConnection con = new SqlConnection(connString);
  con.Open();
  string backgroundcolor;
  SqlDataReader rdrI = null;
  SqlCommand cmdI = null;
  string CommandText = "SELECT *  FROM LOOKUP WHERE ([key] = 'Backgroundcolor')";
   cmdI = new SqlCommand(CommandText, con);
   rdrI = cmdI.ExecuteReader();
   while (rdrI.Read())
  {
   MessageBox.Show(rdrI["Value"].ToString());
  backgroundcolor = rdrI["Value"].ToString();
  form.BackgroundImage = null;
  form.BackColor = Color.FromName(backgroundcolor);
   }

Answers (2)