Geeks With Blogs


Add to Google

Tim Hibbard CEO for EnGraph software

When I build data access layers, I like to define a const for each column in the query like this:

const int CLIENTID = 0; const int STATUS = 1; const int FIRSTNAME = 2;

That way, I can pull data like this:

newClient.Name.FirstName = reader.GetString(FIRSTNAME);

And if something changes in the database, I know I only have to change the field that FIRSTNAME references.

However, sometimes, tables can be quite large and it becomes a pain in the wrist.  So I wrote a class that uses the EnterpriseLibrary and builds the code that defines the const for each column.  Then I can copy and paste it into my code:

This class can be consumed like this:

ExtractFieldNames x = new ExtractFieldNames("myConnectionString"); textBoxResults.Text = x.ExtractConstantsFromTable("myTableName);

The article with the class is here. 


Technorati tags: , , ,
Posted on Wednesday, February 14, 2007 12:54 PM .NET | Back to top

Comments on this post: C# Code to build constants from the database

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Tim Hibbard | Powered by: