A
Alex. O. Koranteng
i have created DAL code and Business layer code. I am using objectdatasource
to point to the select and Update methods. I am also using Enterprise library
3.1 and the GetStoredproc command method to access/modify data for the
gridview. I am getting errors like (1)"Type or namespace could not be found,
(2)'Microsoft.Practices.EnterpriseLibrary.Data.Database' does not contain a
definition for 'GetSprocCommand', (3) The name Northwind does not exist in
the current context. Any suggestions will be appreciated, and below is the
code sample
DAL code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
/// <summary>
/// Summary description for DataAccess
/// </summary>
public class DataAccess
{
public DataAccess()
{
//
// TODO: Add constructor logic here
//
}
public DataSet GetCustomers()
{
//DataSet dsGetCustomer = null;
DataSet dsGetCustomer = null;
DbCommand Command = null;
DataTable dt = new DataTable();
string DbCommand = "CustomerList1";
Database Northwind = DatabaseFactory.CreateDatabase();
DbCommand command = Northwind.GetStoredProcCommand("CustomerList1");
//Northwind.AddInParameter(DbCommand, "Customerid", DbType.Int32,
Customer);
using (IDataReader dr = Northwind.ExecuteReader(command))
{
dt.Load(dr);
}
//return Customers;
return dsGetCustomer;
}
public void UpdateCustomers(string CustomerID, string companyName, string
contactName)
{
string dbcommand = "sp_UpdateCustomerEntLib";
DbCommand command =
Northwind.GetStoredProcCommand("sp_UpdateCustomerEntLib");
DataTable dt = new DataTable();
//Northwind.AddInParameter(DbCommand, "Customerid", DbType.Int32,
Customer);
using (IDataReader dr = Northwind.ExecuteReader(command));
{
dt.Load(dr);
}
}
}
Business Layer Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
/// <summary>
/// Summary description for BizLayer
/// </summary>
public class BizLayer
{
public BizLayer()
{
//
// TODO: Add constructor logic here
//
}
public DataSet GetCustomers()
{
DataAccess dataAcess = null;
try
{
dataAcess = new DataAccess();
return dataAcess.GetCustomers();
}
finally
{
dataAcess = null;
}
}
public void UpdateCustomers(string CustomerID,string contactName)
{
DbCommand dbCommand = null;
Database Northwind = DatabaseFactory.CreateDatabase("Northwind");
dbCommand = Northwind.GetSprocCommand("sp_UpdateCustomerEntLib");
Northwind.ExecuteNonQuery(dbCommand);
}
}
to point to the select and Update methods. I am also using Enterprise library
3.1 and the GetStoredproc command method to access/modify data for the
gridview. I am getting errors like (1)"Type or namespace could not be found,
(2)'Microsoft.Practices.EnterpriseLibrary.Data.Database' does not contain a
definition for 'GetSprocCommand', (3) The name Northwind does not exist in
the current context. Any suggestions will be appreciated, and below is the
code sample
DAL code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
/// <summary>
/// Summary description for DataAccess
/// </summary>
public class DataAccess
{
public DataAccess()
{
//
// TODO: Add constructor logic here
//
}
public DataSet GetCustomers()
{
//DataSet dsGetCustomer = null;
DataSet dsGetCustomer = null;
DbCommand Command = null;
DataTable dt = new DataTable();
string DbCommand = "CustomerList1";
Database Northwind = DatabaseFactory.CreateDatabase();
DbCommand command = Northwind.GetStoredProcCommand("CustomerList1");
//Northwind.AddInParameter(DbCommand, "Customerid", DbType.Int32,
Customer);
using (IDataReader dr = Northwind.ExecuteReader(command))
{
dt.Load(dr);
}
//return Customers;
return dsGetCustomer;
}
public void UpdateCustomers(string CustomerID, string companyName, string
contactName)
{
string dbcommand = "sp_UpdateCustomerEntLib";
DbCommand command =
Northwind.GetStoredProcCommand("sp_UpdateCustomerEntLib");
DataTable dt = new DataTable();
//Northwind.AddInParameter(DbCommand, "Customerid", DbType.Int32,
Customer);
using (IDataReader dr = Northwind.ExecuteReader(command));
{
dt.Load(dr);
}
}
}
Business Layer Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
/// <summary>
/// Summary description for BizLayer
/// </summary>
public class BizLayer
{
public BizLayer()
{
//
// TODO: Add constructor logic here
//
}
public DataSet GetCustomers()
{
DataAccess dataAcess = null;
try
{
dataAcess = new DataAccess();
return dataAcess.GetCustomers();
}
finally
{
dataAcess = null;
}
}
public void UpdateCustomers(string CustomerID,string contactName)
{
DbCommand dbCommand = null;
Database Northwind = DatabaseFactory.CreateDatabase("Northwind");
dbCommand = Northwind.GetSprocCommand("sp_UpdateCustomerEntLib");
Northwind.ExecuteNonQuery(dbCommand);
}
}