Link to home
Start Free TrialLog in
Avatar of edshoro
edshoroFlag for United States of America

asked on

Convert string to system.drawing.color

I am trying to change the color of a control from a srting value in a sql database.
The test value in the field is "black" as a string. I can not seem to convert the string to system.drawing.color.
Below is my code

Dim labelcolor As System.Drawing.Color

           Try
            Dim strSQL As String = "Select * from startup"

            Dim myConnection As New SqlConnection(connectionstring)
            Dim sqlCmd As New SqlCommand(strSQL)
            Dim sqlReader As SqlDataReader
            sqlCmd.Connection = myConnection
            myConnection.Open()
            sqlReader = sqlCmd.ExecuteReader

            If (sqlReader.Read()) Then

                labelcolor = ctype (sqlReader("headerarea2",System.Drawing.Color))
                HeaderLabel.BackColor = labelcolor
               

                            End If
        Catch exp As Exception
            lblerror.Text = exp.ToString
        End Try
Avatar of Hamed Zaghaghi
Hamed Zaghaghi
Flag of Iran, Islamic Republic of image

use
System.Drawing.Color.FromName function
ASKER CERTIFIED SOLUTION
Avatar of Hamed Zaghaghi
Hamed Zaghaghi
Flag of Iran, Islamic Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial