且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找不到Datatable是你缺少程序集或指令

更新时间:2023-11-21 14:38:28

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.