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;
}
what will be the code in stored procedure for this example.
Thanks in advance.