Return a string using EnterpriseLibrary 4.1


This code sample gives a simple example of handling out parameter of stored procedure 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;



5. Declare a method and add the following code



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

Guest Author: Manoj28 Apr 2012

what will be the code in stored procedure for this example.

Thanks in advance.



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