Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Dynamic Enum

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Wright - 17 Sep 2007 22:33 GMT
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
Samuel R. Neff - 18 Sep 2007 03:21 GMT
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
Bob Powell [MVP] - 18 Sep 2007 10:29 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.