I have an enum based on a lookup table in my database. However, when a new
item is added to the lookup table or one is removed, I have to modify the
enum to match. Is there a way to dynamically load the enum when the class
is instantiated? I was thinking a stored procedure to load it but can't
figure out how to do this.
John
Enums are compile-time constants so you can't change them at runtime
based on data. I would instead suggest using a pre-build script to
regenerate the enum based on data or using a code-gen tool.
If the table values can change at runtime, then it's probably not
appropriate to be using an enum in the first place.
HTH,
Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
>I have an enum based on a lookup table in my database. However, when a new
>item is added to the lookup table or one is removed, I have to modify the
[quoted text clipped - 3 lines]
>
>John
Rather than modifying the enum, which is a compiled thing, you should be
populating your lookup table directly from the database using a request.
I would use a datareader to get all the items in the table and then put them
in a list of strings then bind the list to the column / dropdon , grid or
whatever it is you're using to display the list.

Signature
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
>I have an enum based on a lookup table in my database. However, when a new
>item is added to the lookup table or one is removed, I have to modify the
[quoted text clipped - 3 lines]
>
> John
John Wright - 21 Sep 2007 20:28 GMT
This is the route I am going to take. I was thinking an enum would be great
based on table definitions. Not that they would change all that much, but
the do change and I wanted to make sure my enum would capture that. Since I
can't do this, I am going to just access the table directly. Thanks for the
help.
John
> Rather than modifying the enum, which is a compiled thing, you should be
> populating your lookup table directly from the database using a request.
[quoted text clipped - 10 lines]
>>
>> John