Thought I'd just throw out a simple code sample for the (very) simple pattern I use when writing data access code with the Data Access Application Block. This example is for doing a simple object insert (non-transactional) into a DB:

internal static  void AddEmailAddressToContact(Int64 contactId, EmailAddress emAddr)

                                {

                                                string spName = "pr_MedSh_AddEmailAddressToContact";

                                                SqlParameter[] sqlParams = SqlHelperParameterCache.GetSpParameterSet(Global.Config.DBConnectionString,spName);

                                                sqlParams[0].Value = contactId;

                                                sqlParams[1].Value = emAddr.AddressTypeId;

                                                sqlParams[2].Value = emAddr.IsPrimary;

                                                sqlParams[3].Value = emAddr.Address;

                                                SqlHelper.ExecuteNonQuery(Global.Config.DBConnectionString,CommandType.StoredProcedure,spName,sqlParams);

                                }

 

Told you it was simple! This is the pattern I use for all these sort of things. Using a SqlDataReader is just as easy, I wrap the 'SqlDataReader dr = SqlHelper.ExecuteReader' in a 'using' block and very rearely pass it up between layers, preferring instead to use simple custom collections or ArrayLists.

posted on Friday, August 27, 2004 1:38 PM | Print

Comments

No comments posted yet.
Post Comment
Title *  
Name *  
Email
Url
Comment *  
Please add 7 and 1 and type the answer here: