错误1找不到类型或命名空间名称“DAL” [英] Error 1The type or namespace name 'DAL' could not be found

查看:88
本文介绍了错误1找不到类型或命名空间名称“DAL”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用System; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Data.SqlClient;
使用System.Data;
命名空间Management.DAL
{
class DataAccessLayer
{
SqlConnection SqlConnection;

public DataAccessLayer()
{
SqlConnection = new SqlConnection(server = MOHAMED; database = product_DB; Integrated Securit = true);
}

public void open()
{
if(SqlConnection.State!= ConnectionState.Open)
{
SqlConnection.Open ();
}
}
public void关闭()
{
if(SqlConnection.State == ConnectionState.Open)
{
SqlConnection。关();
}
}

public DataTable SelectData(string stored_procedure,SqlParameter [] param)
{
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.CommandText = stored_procedure;

if(param!= null)
{
for(int i = 0; i& lt; param.length; i ++)
{
sqlcmd.Parameters.Add(param [i]);
}
}
SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
DataTable dt = new DataTable();
da.Fill(dt);
返回dt;
}

public void ExecuteCommand(string stored_procedure,SqlParameter [] param)
{
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.CommandText = stored_procedure;

if(param!= null)
{
sqlcmd.Parameters.AddRange(param);
}

sqlcmd.EndExecuteNonQuery();
}
}
}

解决方案

添加包含Management.DAL命名空间的dll作为参考

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace Management.DAL
{
    class DataAccessLayer
    {
        SqlConnection SqlConnection;

        public DataAccessLayer()
        {
            SqlConnection = new SqlConnection("server=MOHAMED; database=product_DB; Integrated Securit=true");
        }

       public void open()
        {
           if(SqlConnection.State != ConnectionState.Open)
           {
               SqlConnection.Open();
           }
        }
        public void Close()
       {
            if(SqlConnection.State==ConnectionState.Open)
            {
                SqlConnection.Close();
            }
       }

        public DataTable SelectData(string stored_procedure, SqlParameter[] param)
        {
            SqlCommand sqlcmd = new SqlCommand();
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.CommandText = stored_procedure;

            if(param !=null)
            {
                for(int i = 0; i < param.length; i++)
                {
                    sqlcmd.Parameters.Add(param[i]);
                }
            }
            SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }

        public void ExecuteCommand(string stored_procedure, SqlParameter[] param)
        {
            SqlCommand sqlcmd = new SqlCommand();
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.CommandText = stored_procedure;

            if (param !=null)
            {
                sqlcmd.Parameters.AddRange(param);
            }

            sqlcmd.EndExecuteNonQuery();
        }
    }
}

解决方案

Add as reference the dll that contains Management.DAL namespace.


这篇关于错误1找不到类型或命名空间名称“DAL”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆