Return a string using EnterpriseLibrary

This code sample gives a simple example of handling out parameter of stored procedure using EnterpriseLibrary.

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
4. In the business layer, class file add reference to

using Microsoft.Practices.EnterpriseLibrary.Data;


public string GetEmployeeId(string strEmpName)
{
string strEmployeeId = string.Empty;
Database objDatabase = DatabaseFactory.CreateDatabase("HRPortal");
DbCommand objDBCommand = objDatabase.GetStoredProcCommand("spHR_GetEmployeeId");
objDatabase.AddInParameter(objDBCommand, "EmpName", DbType.String, strEmpName);
objDatabase.AddOutParameter(objDBCommand, "iEmpId", DbType.String);
objDatabase.ExecuteScalar(objDBCommand);
strEmployeeId = objDatabase.GetParameterValue(objDBCommand, "iEmpId").ToString();
return strEmployeeId;
}

Comments

Popular posts from this blog

SharePoint 2007 - Simple Task Dashboard

MERGE transformation in SSIS