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
|
| Author: Madhu 06 Jul 2007 | Member Level: Bronze Points : 0 |
Use ful article
|