Execute a nonquery using Microsoft.Practices.EnterpriseLibrary.Data.dll

While implementing three-tier architecture, we use Enterprise Library in our web and windows application alike. This code sample gives a simple example of executing a NonQuery using EnterpriseLibrary.Data.dll

Prerequisites:EnterpriseLibrary 4.1

1. Add the reference to Microsoft.Practices.EnterpriseLibrary.Data.dll
2. Add the reference to Microsoft.Practices.EnterpriseLibrary.Common.dll
3. In the web.config file, create the database conection string



< connectionStrings>
< add name="EmployeeData" providerName="System.Data.SqlClient" connectionString="Data Source=EmployeeDataPortal;Initial Catalog=Employee;user id=sa;pwd=HRMaster0098"/>
</connectionStrings>



3. In the business layer, class file add reference to



using Microsoft.Practices.EnterpriseLibrary.Data;



4. Declare a method and add the following code



public void UpdateEmployeeDataCount(String strEmployeeId, string strEmpType)
{
// Create the database connection
Database objDatabase = DatabaseFactory.CreateDatabase("EmployeeData");
// Create the Database Command object, mention which stored procedure it is going to call
DbCommand objDBCommand = objDatabase.GetStoredProcCommand("spEmployee_UpdateEmployeeCount");
// Mention the In Parameter, its datatype and its value
objDatabase.AddInParameter(objDBCommand, "@sEmpId", DbType.String, strEmployeeId);
// Mention the In Parameter, its datatype and its value
objDatabase.AddInParameter(objDBCommand, "@sEmpType", DbType.String, strEmpType);
// Execute the Command object as NonQuery in the Database create by Enterprise Library
objDatabase.ExecuteNonQuery(objDBCommand);
}


Comments

Guest Author: rajani12 Dec 2012

hi this is nice but u have to give clear description about 3tier using Microsoft.Practices.EnterpriseLibrary references and how to insert,update ,delete all operations,please kindely post this code.
thank u for all



  • 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:
    Email: