?
Solved

enum on database values

Posted on 2005-03-03
4
Medium Priority
?
249 Views
Last Modified: 2012-08-13
HI!

Can anybody show me hints to creating a dynamic database based enumeration?

Lets say I have a Country class and this class can used with ie. "Country.Germany" or "Country.Taiwan" - each representing the PK values from the Country table in DB. How do I make a class that automatically takes new rows from the Country table in DB into the enum?

Thanx in advance.
0
Comment
Question by:korona5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Expert Comment

by:gena17
ID: 13450327
Hi, korona5.

What do you mean by "automatically takes new rows from the Country table in DB into the enum" ?
Why do you want to use your enum if its properties are created dinamically?
Do you want to generate C# code for the enum?

Gena
0
 

Author Comment

by:korona5
ID: 13456763
Lets say I have a Country class today - based on database values from a Country table - and I use it on my GUI like:

Country _Country = new Country(Country.Countries.Germany);

This way I don't have to do:

Country _Country = new Country(738);

"738" tells me nothing when reading my code, so I have to look up the database to see that 738 = Germany, or assume that programmers will write comments to the code and not change database values.

I can handwrite this enum each time I add a new Country to the database, but isn't it possible to make the code dynamically reflect changes in the database, so when I one day wish to add the Country "Congo", the class automatically can be instantiated with:

Country _Country = new Country(Country.Countries.Congo);
0
 
LVL 8

Accepted Solution

by:
gena17 earned 500 total points
ID: 13469668
Hi,

I just want to be sure I get you in correct way.
Say, your DB doesn't contain Congo.
I've compiled your application and have an executable.
Now you add Congo to the DB.
To use:
  Country _Country = new Country(Country.Countries.Congo);
you must go to your application, write new code and re-compile it.
In this case you need to add the enum member Congo manually.
Or you can write a small application that reads the DB and creates C# class code with enum members you want. After that you need to re-compile.

If you don't want re-compile you can use a class that determines countries by string, not enum.

Hope this helps.

Gena
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question