I have a class called CatalogAccess
in the app_Code
folder and a DataList
user control in a folder called UserControls
which is in the root folder. The UserControl
is used to display a list of departments that are being pulled in the CatalogAccess
. I call the GetDepartments
function in the CatalogAccess
class like this:
list.DataSource = CatalogAccess.GetDepartments();
list.DataBind();
However, intelisense keeps telling me that
The name CatalogAccess does not exist in the current context
CatalogAccess class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Common;
namespace techniccashregister.App_Code
{
// Product catalog business tier component
public static class CatalogAccess
{
static CatalogAccess()
{
//
// TODO: Add constructor logic here
//
}
public static DataTable GetDepartments()
{
// Get a configured DbCommand object
DbCommand comm = GenericDataAccess.CreateCommand();
// Set the stored procedure name
comm.CommandText = "GetDepartments";
// Exectute the store procedure and return the results
return GenericDataAccess.ExecuteSelectCommand(comm);
}
}
}
User Control
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using techniccashregister.App_Code;
namespace techniccashregister.UserControls
{
public partial class DepartmentsList : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
list.DataSource = CatalogAccess.GetDepartments();
list.DataBind();
}
}
}
Class Accessing data
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Common;
namespace techniccashregister.App_Code
{
// This class contains generic data access functionality to be accessed from the business tier
public static class GenericDataAccess
{
// Static constructor
static GenericDataAccess()
{
//
// TODO: Add constructor logic here
//
}
// Executes a commmand and returns the results as a DataTable object
public static DataTable ExecuteSelectCommand(DbCommand command)
{
// The DataTable to be returned
DataTable table;
// Execute the command, making sure the connection gets closed in the end
try
{
// Open the data connection
command.Connection.Open();
// Execute the command and save the results in a DataTable
DbDataReader reader = command.ExecuteReader();
table = new DataTable();
table.Load(reader);
// Close the reader
reader.Close();
}
catch (Exception ex)
{
Utilities.LogError(ex);
throw;
}
finally
{
// Close the connection
command.Connection.Close();
}
return table;
}
// Creates and prepares the new DbCommand object on a new connection
public static DbCommand CreateCommand()
{
// Obtain the database provider name
string dataProviderName = technicConfiguration.DbProviderName;
// Obtain the database connection string
string connectionString = technicConfiguration.DbConnectionString;
// Create the new data provider factory
DbProviderFactory factory = DbProviderFactories.GetFactory(dataProviderName);
// Obtain a database-specific connection object
DbConnection conn = factory.CreateConnection();
// Set the connection string
conn.ConnectionString = connectionString;
// Create a database-specific command object
DbCommand comm = conn.CreateCommand();
// Set the command type to stored procedure
comm.CommandType = CommandType.StoredProcedure;
// Return the initialized command object
return comm;
}
}
}
Does anyone know what can I do to fix this? Thanks in advance