不包含定义,并且没有可以找到接受类型的第一个参数的扩展方法(您是否缺少using指令或引用?) [英] does not contain a definition for and no extension method accepting a first argument of type could be found(are you missing a using directive or an reference?)
问题描述
先生,我是一个新鲜的,我得到以下错误,无法解决自己请帮助我
DAL的MYCODE
名称空间DAL
{
公共类DalEmployee
{
SqlConnection con = new SqlConnection(data source = .\\SQLEXPRESS;集成安全性= SSPI; AttachDBFilename = | DataDirectory | Database1.sdf;用户实例= true);
public DataSet ds; SqlDataAdapter da; SqlCommandBuilder bldr;
public DalEmployee()
{
da = new SqlDataAdapter(Select * from Employe,con);
ds = new DataSet();
da.Fill(ds,Employee);
da.FillSchema(ds,SchemaType.Source,员工);
bldr =新的SqlCommandBuilder(da);
}
public void UpdateDB()
{
da.Update(ds,Employee);
}
}
}
BLL中的MYCODE
使用 DAL;
命名空间 BLL
{
public class BllEmployee
{
int Esalary,Eid,Edeptno; DataRow Rec;
string Ename,Edesignation; DateTime Edoj;
DalEmployee objdal = new DalEmployee();
public int PEid
{
set { Eid = value; }
get { return Eid; }
}
public string PEname
{
set { Ename = value; }
get { return Ename; }
}
public string PEdesignation
{
set { Edesignation = value; }
get { return Edesignation; }
}
public DateTime PEdoj
{
set { Edoj = value; }
get { return Edoj; }
}
public int PEsalary
{
set { Esalary = value; }
get { return Esalary; }
}
public int PEdeptno
{
set { Edeptno = value; }
get { return Edeptno; }
}
BllEmployee obj = new BllEmployee();
public void InsertRec()
{
此处 - > - > Rec = obj 。 ds .Tables [0] .NewRow(); // 我在这里获得错误s
Rec [0] = Eid;
Rec [1] = Ename;
}
- > - > // BLL.BllEmployee不包含定义对于ds和没有扩展方法ds接受类型BLL.BllEmployee'的第一个参数可以找到(你是否缺少一个使用指令或一个seeembly引用?)
这里我没有得到数据集ds;
你好!
这个错误意味着变量/ propertyds
未在BllEmployee类中定义。
如果您有BllEmployee的源代码,您可以更改它以添加任何类型的变量ds应该是指。
不幸的是我不知道你的问题是什么ds
应该是是...
@Mike Meinz - 好点! :-)
你需要定义自己应该是什么ds。
嗯...它没有。
类中没有DataSet的定义,更像是一个名为ds的定义,所以它非常正确地说你不能这样做:ds不作为成员存在这个班级
你的意思是使用objdal
而不是obj
sir, iam a fresher and iam getting the following error and could't solve myself please help me out
MYCODE IN DAL IS
namespace DAL
{
public class DalEmployee
{
SqlConnection con = new SqlConnection("data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Database1.sdf;User Instance=true");
public DataSet ds; SqlDataAdapter da; SqlCommandBuilder bldr;
public DalEmployee()
{
da = new SqlDataAdapter("Select * from Employe", con);
ds = new DataSet();
da.Fill(ds, "Employee");
da.FillSchema(ds, SchemaType.Source, "Employee");
bldr = new SqlCommandBuilder(da);
}
public void UpdateDB()
{
da.Update(ds, "Employee");
}
}
}
MYCODE IN BLL IS
using DAL;
namespace BLL
{
public class BllEmployee
{
int Esalary, Eid, Edeptno; DataRow Rec;
string Ename, Edesignation; DateTime Edoj;
DalEmployee objdal = new DalEmployee();
public int PEid
{
set { Eid = value; }
get { return Eid; }
}
public string PEname
{
set { Ename = value; }
get { return Ename; }
}
public string PEdesignation
{
set { Edesignation = value; }
get { return Edesignation; }
}
public DateTime PEdoj
{
set { Edoj = value; }
get { return Edoj; }
}
public int PEsalary
{
set { Esalary = value; }
get { return Esalary; }
}
public int PEdeptno
{
set { Edeptno = value; }
get { return Edeptno; }
}
BllEmployee obj = new BllEmployee();
public void InsertRec()
{
here ->-> Rec = obj.ds.Tables[0].NewRow();// Here iam getting the error s
Rec[0] = Eid;
Rec[1] = Ename;
}
->->// BLL.BllEmployee does not contain a definition for ds and no extension method ds accepting afirst argument of type BLL.BllEmployee' could be found(are you missing a using directiveor an seeembly reference?)
Here iam not getting the dataset ds;
Hello!
This error means that the variable/propertyds
is not defined in the class BllEmployee.
If you have the source code to BllEmployee, you could change it to add whatever sort of variable ds is supposed to refer to.
Unfortunately I have no idea from your question whatds
is supposed to actually be...
@Mike Meinz - good point! :-)
You need to define whatever ds is supposed to be yourself.
Well...it doesn't.
There is no definition of a DataSet anywhere in your class, much less one called "ds", so it is quite correctly saying "You can't do this: ds does not exist as a member of this class"
Did you mean to useobjdal
instead ofobj
?
这篇关于不包含定义,并且没有可以找到接受类型的第一个参数的扩展方法(您是否缺少using指令或引用?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!