I want to have an Enum that's built from a database query and I'm stuck at how to do it. My thought was to have a method that returns a list of strings and use that to fill the Enum, but I'm unsure if that's possible or the proper way to do it. The table that the Enum will be built from will change very infrequently. What's a good way to get at this?
enum DrugColor
{
}
private List<string> BuildEnum()
{
List<string> EnumList = new List<string>();
using (SqlConnection con = new SqlConnection(cs))
{
using (SqlCommand cmd = new SqlCommand("select color from DrugColors", con))
{
con.Open();
cmd.CommandType = CommandType.Text;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
string colorName;
colorName = rdr["Color"].ToString();
EnumList.Add(colorName);
}
}
return EnumList;
}
}