Resources » .NET programming » .NET Framework

About SqlHelper Class


Posted Date: 03-Jul-2007  Last Updated:   Category: .NET Framework    
Author: Member Level: Gold    Points: 10


This article helps you to access the Sql Helper Class and example of code snippet for SqlHelper Class



Introduction


We might know how to use ADO.Net concepts like SqlConnection,SqlDatAdapter and SqlCommand.But using this we want to write "n" no.of lines to connect with backend.To reduce these lines we are using SqlHelper Class.

Namespace for SqlHelper



SqlHelper Class comes from the namespace Microsoft.ApplicationBlocks.Data.This is a third tool party we should get from msdn and install and add the dll file to our project.

Methods in SqlHelper Class




  • ExecuteDataSet

  • ExecuteNonQuery

  • ExecuteReader

  • ExecuteScalar

  • ExecuteXmlReader



I think u know about these methods.The syntax to use these methods

Syntax
SqlHelper.ExecuteDataSet(SqlConnection connection,string spname,params object[] parameter)

We need a connection string,a sql query string and the values for the parameters.

Example

try
{
SqlHelper.ExecuteNonQuery(DataAccess.ConnectionString, CommandType.StoredProcedure, "empinsert", new SqlParameter ("@EmpNo",empno), new SqlParameter("@EmpName",ename),new SqlParameter ("@EmpSal",empsal));
} catch (Exception ee)
{
MessageBox.Show(ee.Message );

}



Summary



The usage of SqlHelper Class is to reduce the no.of.lines for connecting the database through SqlClient or Oledb


Did you like this resource? Share it with your friends and show your love!

Responses to "About SqlHelper Class"
Author: Madhu    06 Jul 2007Member Level: Bronze   Points : 0
Use ful article


Guest Author: Sudarshan     08 Oct 2012
Very useful article....


Guest Author: Sudheer P     17 Feb 2013
Thank you very much. It is very useful and you explained very clearly.


Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Phagu Mahato
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India