找不到Datatable是你缺少程序集或指令 [英] cannot find Datatable are u missing assembly or directive

查看:239
本文介绍了找不到Datatable是你缺少程序集或指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的业务逻辑中编写了以下代码,并且它产生了一些错误,比如使用指令或汇编函数丢失了。但我已经检查了很多时间的引用,但无法理解为什么会出现这个错误。以下是我的BAL代码:

使用Datalgc; 
使用DL;
//在这一层中,我们必须声明prop。,方法,如果我想插入只是创建一个函数/方法来插入值,并在按钮点击时调用它.cs文件

命名空间Buss
{
公共类BusinessLogic
{
GenralFunction gf = new GenralFunction();

公共类属性
{
private string _Name;
private int _DOB;
private string _Add;
private int _Phno;
private string _Country;
private string _State;
private string _Distt;

公共字符串名称
{
get {return _Name; }
set {_Name = value; }
}
public int DOB
{
get {return _DOB; }
set {_DOB = value; }
}
公共字符串添加
{
get {return _Add; }
set {_Add = value; }
}
public int Phno
{
get {return _Phno; }
set {_Phno = value; }
}
公共字符串国家
{
get {return _Country; }
set {_Country = value; }
}
公共字符串状态
{
get {return _State; }
set {_State = value; }
}
公共字符串Distt
{
get {return _Distt; }
set {_Distt = value; }
}
}
public DataTable userdetails()//我在数据库中的表名
{
DataTable dt = new DataTable();
dt = gf.Filldatatablevalue(null,spuserdetails,dt,null);
返回dt;
}
public int Insert()
{
int result = 0;
SqlParameter [] parameters = new SqlParameter [7];
parameters [0] = new SqlParameter(@ Name,SqlDbType.VarChar,4)
{Value = Name};
parameters [1] = new SqlParameter(@ DOB,SqlDbType.Datetime,2)
{Value = DOB};
parameters [2] = new SqlParameter(@ Addr,SqlDbType.VarChar,3)
{Value = Addr};
parameters [3] = new SqlParameter(@ phn,SqlDbType.Int,2)
{Value = phn};
parameters [4] = new SqlParameter(@ Country,SqlDbType.VarChar,2)
{Value = Country};
parameters [5] = new SqlParameter(@ State,SqlDbType.VarChar,70)
{Value = State};
parameters [6] = new SqlParameter(@ City,SqlDbType.VarChar,70)
{Value = City};
result = gf.UpdateData(parameters,spuserdetails);
返回0;
}

}

}



价值=姓名等显示当前上下文中不存在Name的错误。在添加BAL的命名空间之后(这里Buss到我的代码隐藏文件我无法使用属性。我在.cs文件中做的如下:

 BusinessLogic obj = new BusinessLogic(); 

并且使用此对象我想为属性分配值但不能。为什么?帮帮我。谢谢。

解决方案

1.你需要包含System.Data

2.因为一些奇怪的原因你将类属性包装在一个单独的类中,这就是Name不存在的原因在这种情况下

3.另外因为你把你的房产包裹在一个单独的类中。



并回答未提出的问题:

因为您没有Addr属性,所以将其命名为Add。与其他无法找到的属性相同。


i have written the following code in my business logic and it is producing some error like are u missing using directive or assembly function. But i have check the references for many time and not able to get why this error is coming. the following is my BAL code:

using Datalgc;
using DL;
                 // In this layer we have to declare prop.,methods like if i want to insert just create a function/method for inserting values and call it on button click .cs file

namespace Buss
{
    public class BusinessLogic
    {
        GenralFunction gf = new GenralFunction();
       
        public class property
        {
            private string _Name;
            private int _DOB;
            private string _Add;
            private int _Phno;
            private string _Country;
            private string _State;
            private string _Distt;

            public string Name
            {
                get { return _Name; }
                set { _Name = value; }
            }
            public int DOB
            {
                get { return _DOB; }
                set { _DOB = value; }
            }
            public string Add
            {
                get { return _Add; }
                set { _Add = value; }
            }
            public int Phno
            {
                get { return _Phno; }
                set { _Phno = value; }
            }
            public string Country
            {
                get { return _Country; }
                set { _Country = value; }
            }
            public string State
            {
                get { return _State; }
                set { _State = value; }
            }
            public string Distt
            {
                get { return _Distt; }
                set { _Distt = value; }
            }
       }
        public DataTable userdetails()                                    // my table name in database
        {
             DataTable dt = new DataTable();
             dt = gf.Filldatatablevalue(null, "spuserdetails", dt,null);
            return dt;
        }
        public int Insert()
        {
            int result = 0;
              SqlParameter[] parameters = new SqlParameter[7];
            parameters[0] = new SqlParameter("@Name", SqlDbType.VarChar, 4) 
            { Value = Name };
            parameters [1] = new SqlParameter("@DOB", SqlDbType.Datetime, 2)
            { Value = DOB };
            parameters[2] = new SqlParameter("@Addr", SqlDbType.VarChar, 3) 
            { Value = Addr };
           parameters[3] = new SqlParameter("@phn", SqlDbType.Int, 2) 
           { Value = phn};
            parameters[4] = new SqlParameter("@Country", SqlDbType.VarChar, 2) 
            { Value = Country };
            parameters[5] = new SqlParameter("@State", SqlDbType.VarChar, 70) 
            { Value = State };
            parameters[6] = new SqlParameter("@City", SqlDbType.VarChar, 70) 
            { Value = City };
            result = gf.UpdateData(parameters, "spuserdetails");
            return 0;
        }
      
    }
        
}


also

Value = Name

and etc in insert method are showing error that Name does not exist in the current context. also after adding the namespace of BAL (here Buss to my codebehind file i m not able to use the properties. what i have done in .cs file is as follows:

BusinessLogic obj = new BusinessLogic();

and with this object i want to assingn values to the properties but can't. Why? Help me .Thanks.

解决方案

1. You need to include System.Data
2. Because for some strange reason you have wrapped your class properties in a separate class and that is why Name does not exist in that context
3. Also because you have wrapped your properties in a separate class.

And to answer the unasked question:
Because you do not have an "Addr" property, you named it "Add". Same with the other properties that can't be found.


这篇关于找不到Datatable是你缺少程序集或指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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