Return Datatable using EnterpriseLibrary 4.1
This code sample gives a simple example of ExecuteDataSet using EnterpriseLibrary
This code sample gives a simple example of ExecuteDataSet 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 DataTable GetArticleContent()
{
// 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("sp_GetEmployeeMasterData");
// Mention the In Parameter, its datatype and its value
objDatabase.AddInParameter(objDBCommand, "EmpId", DbType.String, this.EmployeeId);
// Create a DataTable object and use the EnterpriseLibrary.Data's ExecuteDataSet method to return the datatable
DataTable objEmployeeData = objDatabase.ExecuteDataSet(objDBCommand).Tables[0];
// return the Datatable
return objEmployeeData;
}
Thanks for sharing.