Tuesday, August 03, 2004

VJs Tip Of The Day - August 3rd 2004

Design Days - Data Access Ways

This is just a small little thought, which I thought, can be shared... When we try to access data from a table in DataSet many a times we have to use the name of the columns... We have multiple Datagrids bound to each table and many other controls of your page also access data from these tables... Now, just in case your column name changes in the table you would want to have minimum impact on the stuff that you have to change...
As a solution to this you can have DataDefinition class... This class can just return back the name of the columns as properties, you can define these light weight classes if you have less number of tables to be accessed... In any case if you do not follow this approach then it is always advisable to have constants declared at a common location and store your column names in there....
You can later use either these constants or light weight classes to get the column names...

PS: Do note that by introducing such things you can make your design more maintainable but sometimes loose on performance... Take decisions on the basis of what is ideal for your situation... Don't sue a poor fella like me for suggesting, you anyways won't get much... :-)

Kathleen Dollard, Microsoft MVP adds the below:
Use enums. Much faster and far more maintainable....

No comments: