views:

670

answers:

3

I have a table full of id's,categories and weights that I need to reference in my program as I read in records that contain those categories. What is the most efficient method to read those from a database and put into a structure that I can reference?

The ID's (and possibly the names) would be unique

Data might look like:

ID,Category,Weight
1,Assignment,5
2,Test,10
3,Quiz,5
4,Review,3
+2  A: 

Your best bet is to read in your table using a DataReader, and put each row into an object containing Category and Weight, then each object into a Dictionary.

Jess
A: 

If you want to avoid a database hit to fetch static data, you can hard-code the values into a common class in your solution. A Dictionary collection would work fine here too.

The trade off of course is; 2 locations to manage for any possible future changes.

Nick Josevski
+2  A: 

If you're using a later version of .NET, you could always use Linq to just grab that data for you.

Pete OHanlon