UserControl无法识别app_Code中的类

时间:2015-01-28 15:18:04

标签: c# asp.net user-controls

我在CatalogAccess文件夹中有一个名为app_Code的类,在根文件夹中名为DataList的文件夹中有一个UserControls用户控件。 UserControl用于显示CatalogAccess中提取的部门列表。我在GetDepartments类中调用CatalogAccess函数,如下所示:

list.DataSource = CatalogAccess.GetDepartments();
list.DataBind();

但是,知识分子一直在告诉我

  

当前上下文中不存在名称CatalogAccess

CatalogAccess类

    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);
        }
    }
}

用户控制

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();
        }
    }
}

类访问数据

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;
        }
    }
}

有谁知道我该怎么做才能解决这个问题?提前致谢

0 个答案:

没有答案