By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,915 Members | 1,315 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,915 IT Pros & Developers. It's quick & easy.

Dynamic Enum

P: n/a
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
Sep 17 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a

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.

On Mon, 17 Sep 2007 15:33:52 -0600, "John Wright"
<ri***********@hotmail.comwrote:
>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
Sep 18 '07 #2

P: n/a
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.

--
--
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.
"John Wright" <ri***********@hotmail.comwrote in message
news:u1****************@TK2MSFTNGP02.phx.gbl...
>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
Sep 18 '07 #3

P: n/a
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
"Bob Powell [MVP]" <bo*@spamkillerbobpowell.netwrote in message
news:35**********************************@microsof t.com...
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.

--
--
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.
"John Wright" <ri***********@hotmail.comwrote in message
news:u1****************@TK2MSFTNGP02.phx.gbl...
>>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

Sep 21 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.