473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 6282

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 want to create a 2 dimensional array, a 'array of...
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 references the dynamically generated dll. If I...
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 system which accepts 'commands' from a socket and...
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 database as strings. In my application that...
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 corporate NOC, and administered by the IT group there. ...
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 name of the enum it works, no suprise. Question...
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 dynamically. I have ran this program with a file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.