472,338 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,338 software developers and data experts.

Dynamic Enum

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
3 6198

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bob Shafer | last post by:
Is it possible to create dynamic enumerators in Visual Basic .Net? For example, an enumurator that provides a dropdown of available SQL servers?
6
by: Materialised | last post by:
Hi Everyone, I apologise if this is covered in the FAQ, I did look, but nothing actually stood out to me as being relative to my subject. I...
8
by: Eyeawanda Pondicherry | last post by:
I have put some code together that creates an enum dynamically from some database values. The enum can be read perfectly by an application that...
2
by: Chowdary Doppalapudi | last post by:
Hi All Is there any way to create the Enum dynamically from database table. Thank Chowdary D
15
by: rwf_20 | last post by:
I just wanted to throw this up here in case anyone smarter than me has a suggestion/workaround: Problem: I have a classic producer/consumer...
4
by: mark.olszowka | last post by:
I am writing a generic property table as part of my application property_name property_type property_value All information is stored in the...
9
by: Mike Hofer | last post by:
BACKGROUND: We've designed a Website for a client that will be deployed across multiple physical locations. The site will be hosted from a...
4
by: Steve Teeples | last post by:
Given this definition of an enum: enum MyEnum { d1=1, d2=2 } Is there a way to dynamically create this same enum at runtime? I want to
6
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
i'm trying to modify some code to accept an enum then use reflection to fill a dropdown list. If i name the type directly, replace enm with the real...
21
by: arnuld | last post by:
I have created a program to print the input words on stdout. Input is taken dynamically from stdin. In each word, each input character is allocated...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.