Data Access Block Helper

Topics: Data Access Application Block
Jun 11, 2009 at 11:38 AM

I'm trying to create a wrapper/helper class for the Data Access Block 4.1.  I've seen a few examples but nothing that handles explict parameter declaraction.  Are there any examples of a SQLHelper like class for the ata Access Block 4.1.

 

Thanks.

 

Jun 15, 2009 at 5:40 AM

There's no exposed method from the Database class which explicitly creates a DbParameter object.  But you could do a factory class which can create any type of DbParameter by getting the type of a Database object.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 15, 2009 at 8:30 PM

Thanks for the quick response.  Do you have any quick samples you could point me to?  Thanks.

Jun 16, 2009 at 8:29 AM

Here is a sample code: You can create a method like this in a class, where in you pass the databaseinstance as parameter, then determine the type of the database and create the parameter accordingly. I'm just showing you the idea but you can modify this to what code that fits you.

 

  public static DbParameter CreateParameter(Database db)

        {

            if (db.GetType() == typeof(SqlDatabase))

            {

                return new SqlParameter();

            }

            return null;

        }

 

 

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com