Databound Enum?

E

Ernie

I have enums in a .cs class that have Ids which I manually match to
correspond with PKs (primary keys) that exist in an "Admin" database
table. Right now I just make sure the enum Ids match the corresponding
PKs. Is there a way to bind an enum to a dataset so that on
application load the enums are filled with database values and not my
hard-coded values. This way I don't have to edit the enums is the PKs
ever change and if rows are added/deleted.

I realize that enums are really constants that are compiled into the
dll, but know that others must have come across this same issue.

I just want something non-manual. Many thanks for any help.

C#
-------------------------------------------------------------
public enum AdminType //must match database PKs for each item
{
TGH = 5,
TWH,
Corporate,
Master
}

Admins database table
 
M

Mountain Bikn' Guy

I'll offer a quick thought, although I admit I haven't studied your
situation in detail:
consider using static readonly ints to hold the values. Then you can
probably initialize them from the PK's.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top