Sunday, November 16, 2008

DB Tables for Static Values? Puh-leez!

A couple of developers believe strongly that values for every dropdown list should come from the database, even if it's something like gender and marital status. I mean this is stuff that never changes - I wouldn't wake up to read the newspaper headline on a new gender being introduced unless I lived in mutant city at Chernobyl or Hiroshima.

In a traditional C program, you can use constants to keep track of the values for globally static data. For an ASP.NET application, it makes perfectly good sense to declaratively set the values in the dropdown lists. If you must keep the values as (numeric) IDs, you might as well use an enumeration. To support a null, you can either use nullable types (.NET 2.0 feature) or add a NotSpecified as the first enumeration value. If you have absolutely got to store values in the database, you could create a stored procedure that returns values from a temporary table or put together the values in a single dataset using SELECT and UNION. There's no use adding extra disk I/O or taking up cache space for something you know will absolutely never change!

No comments: