C# 不一致的可访问性:正确的类型';数据库';比酒店更难访问';BaseClass.dtBase';
请有人帮助解决以下错误: 可访问性不一致:正确类型的“数据库”不易访问 而不是属性“BaseClass.dtBase” 由于错误消息不一致,我无法运行我的程序 我的错误是dtBase基于受保护的数据库{get;set;},始终为红线 这是我的送货课C# 不一致的可访问性:正确的类型';数据库';比酒店更难访问';BaseClass.dtBase';,c#,C#,请有人帮助解决以下错误: 可访问性不一致:正确类型的“数据库”不易访问 而不是属性“BaseClass.dtBase” 由于错误消息不一致,我无法运行我的程序 我的错误是dtBase基于受保护的数据库{get;set;},始终为红线 这是我的送货课 namespace Payroll_System { public class BaseClass { protected Database dtBase { get; set; } public B
namespace Payroll_System
{
public class BaseClass
{
protected Database dtBase { get; set; }
public BaseClass()
{
dtBase = new Database();
}
public string DBText(string Value)
{
return string.Format("{0}", Value).Replace("'", "''");
}
}
public class Employee: BaseClass
{
public Employee()
{
}
public string IDNo { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string ContactNo { get; set; }
public string Designation { get; set; }
public string Gender { get; set; }
public string PhilHealthNo { get; set; }
public string PhilHealth { get; set; }
public string SSSNo { get; set; }
public string SSS { get; set; }
public string eDate { get; set; }
public void Insert()
{
dtBase.CommandText("INSERT into Employee(eIDNo, eName, eAddress, eContactNo, eDesignation, eGender, ePhilHealthNo, ePhilHealth, eSSSNo, eSSS, edate) values(@IDNo, @Name, @Address, @ContactNo, @Designation, @Gender, @PhilHealthNo, @PhilHealth, @SSSNo, @SSS");
dtBase.AddParameter("@IDNo", this.IDNo);
dtBase.AddParameter("@Name", this.Name);
dtBase.AddParameter("@Address", this.Address);
dtBase.AddParameter("@ContactNo", this.ContactNo);
dtBase.AddParameter("@Designation", this.ContactNo);
dtBase.AddParameter("@Gender", this.Gender);
dtBase.AddParameter("@PhilHealthNo", this.PhilHealthNo);
dtBase.AddParameter("@PhilHealth", this.PhilHealth);
dtBase.AddParameter("@SSSNo", this.SSSNo);
dtBase.AddParameter("@SSS", this.SSS);
dtBase.AddParameter("@Date", this.eDate.ToString());
dtBase.Execute();
}
}
}
我猜
数据库
被声明为内部数据库。(如果未声明为公共
,则默认为内部
)
此代码:
public class BaseClass
{
protected Database DtBase { get; set; }
}
表示此库外部的代码可以创建从BaseClass
继承的新类,并且此新类应该能够通过DtBase
成员访问数据库
类型的项。但这是一个错误,因为数据库
不是公共的,在库外无法访问
一种选择是将数据库
声明为公共
public class Database
{
}
public class BaseClass
{
protected internal Database DtBase(...) {}
}
如果C#能够将可访问性设置为
受保护和内部
,那就太好了。但是,事实证明你不能这么做。(protectedinternal
并不表示您可能会自动认为它的意思,请参见)您的类数据库在哪里?如果在类定义之前附加public class
,该怎么办?命名空间Payroll_System{class Database{public static SqlConnection sqlConn=new SqlConnection();sqlcomm命令comm;public string ConnectionString{get;private set;}public Database():this(“dbPayrollSystem”){}公共数据库(字符串配置){ConnectionString=ConfigurationManager.ConnectionStrings[config].ConnectionString;}}}}请编辑您的问题以包含该代码。因为它是错误的。使基类受保护的内部
无助于解决问题。受保护的内部
是“或”,而不是“和”。关于添加“AND”变体,已经进行了一些讨论,但在C#中尚未出现。关于@AndrewShepherd的语言提案,谢谢。我的数据库没有公开。类数据库。我现在可以运行我的程序了。