Using Data Access Application Block for .NET 2.0

DAAB definitely saves the lines of codes to be written for data access. The sample provided below doesn’t include DAAB, but some general codes in .net 2.0 for data access:

       string connectionString = (string)ConfigurationSettings.AppSettings["ConnectionString"];

       SqlConnection connection = new SqlConnection(connectionString);

       SqlCommand command = new SqlCommand("INSERT_PERSON", connection);

       command.CommandType = CommandType.StoredProcedure;

       command.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 50));

       command.Parameters["@Name"].Value = "Ashraf";

       command.Parameters.Add(new SqlParameter("@Age", SqlDbType.NVarChar, 10));

       command.Parameters["@Age"].Value = "27";

       connection.Open();

       command.ExecuteNonQuery();

       connection.Close();

 The task can be done using DAAB very simply:

 //using Microsoft.ApplicationBlocks.Data;

 SqlHelper.ExecuteNonQuery(connection,"INSERT_PERSON", new  SqlParameter("@Name","Ashraf") , new SqlParameter("@Age", "27") );

Print | posted on Friday, July 07, 2006 3:53 PM

Comments on this post

No comments posted yet.

Your comment:

 (will show your gravatar)
 
Please add 8 and 3 and type the answer here: