1

Why should we use sql helper class in our application.What difference between sql helper class and simple class.In which situation sql Helper should used.Please define structure of class.

Vishal Nagra
  • 113
  • 2
  • 3
  • 8
  • The SqlHelper class just makes the Data Access Layer more compact and reusable across various applications. please go through http://www.codeproject.com/Tips/555870/SQL-Helper-Class-Microsoft-NET-Utility – d.Siva Jul 24 '13 at 04:56

1 Answers1

5

SqlHelper is intended to consolidate mundane, repetitive code that is written time and time again in data access layer components of ADO.NET applications, like this:

using Microsoft.ApplicationBlocks.Data;
SqlHelper.ExecuteNonQuery(connection,"INSERT_PERSON", 
    new SqlParameter("@Name",txtName.Text),
    new SqlParameter("@Age",txtAge.Text));

Instead of this:

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 = txtName.Text;
command.Parameters.Add(new SqlParameter("@Age",SqlDbType.NVarChar,10));
command.Parameters["@Age"].Value = txtAge.Text;
connection.Open();
command.ExecuteNonQuery();
connection.Close();

It is part of the Microsoft Application Blocks framework.

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80