Geeks With Blogs

News



Add to Google

Tim Hibbard CEO for EnGraph software

I have a couple helper methods that I use all the time during my data access layer.  I figured I might as well post them and hopefully help others out.

I use the code from this article to pull my field names, that way I can build code like this:

public override IEntity PopulateFromOpenIDataReader(IDataReader dr)
{
    const int ID = 0;
    const int NAME = 1;
    const int COMMENT = 2;
    const int ADDRESS1 = 3;
    const int ADDRESS2 = 4;

    Doctor rv = new Doctor();

    rv.ID = (int)DataValidation.GetValueFromDR(dr, ID, 0);
    rv.StopName = DataValidation.GetValueFromDR(dr, NAME);
    rv.Comment = DataValidation.GetValueFromDR(dr, COMMENT);
    rv.Address.Address1 = DataValidation.GetValueFromDR(dr, ADDRESS1);
    rv.Address.Address2 = DataValidation.GetValueFromDR(dr,ADDRESS2);
    return rv;
}
 

The article with the DataValidation class code is here.

 

Technorati tags: , , ,
Posted on Thursday, May 3, 2007 1:11 PM .NET | Back to top


Comments on this post: C# code for pulling data out of an IDataReader

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


Copyright © Tim Hibbard | Powered by: GeeksWithBlogs.net