Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 511
  • Last Modified:

Typed Dataset and Enum States

I have a simple database that has a customers table.  One of the fields is for the state in which the customer resides.  I was wondering if I put a states table in, with all the state names and abbreviations, if there was a way to create code so that I could do the following:

dim myCustomerTable as new CustomersTable
myCustomer.Item(0).State = States.Florida.FullName

Or simply

myCusomer.Item(0).State = States.Florida

I can see this being possible strictly in code using some sort of enum field, but I would like the possible values to come from the table in the database not from code.

It seems like this would be a very convenient thing to have happen, but I have not been able to find a way to do this myself.

1 Solution
I think what you are talking about is a dynamic enumeration. I’m not sure if this is possible with the current version of the .net framework.

One thing you might try though, create a small app that writes code for you. This app could be as simple as a form with a multi line textbox and a button on it. When you click the button the program will goto the table you choose, pull data from it and create the code necessary to have an enum of this type.

Next you can copy that code from the textbox into your program.

This idea is not ideal because obviously when you change the database the enum does not change too.

Also keep in mind that enums are kind of like constants. After the program compiles they don’t change unless you make a change in the code and recompile.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now