0
votes

Please can someone help with the following error:

Inconsistent accessibility: proper type 'Database' is less accessible than property 'BaseClass.dtBase'

I cannot run my program due to error message of inconsistent.

My error is dtBase on Protected Database {get; set;}, always red line.

Here's my delivery class.

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();
        }
    }
}
1
Where is your class Database? What if you append public class before the class definition? - Patrick Hofman
namespace Payroll_System { class Database { public static SqlConnection sqlConn = new SqlConnection(); SqlCommand comm; public string ConnectionString { get; private set; } public Database() : this ("dbPayrollSystem") { } public Database(string config) { ConnectionString = ConfigurationManager.ConnectionStrings[config].ConnectionString; } } } - dhaJAY
Please edit your question to include that code. - Patrick Hofman

1 Answers

0
votes

My guess is that Database is declared as internal. (If it is not declared public then it defaults to internal)

This code:

public class BaseClass
{
     protected Database DtBase { get; set; }
}

implies that code external to this library can create a new class that inherits from BaseClass, and this new class should be able to access an item of type Database via the DtBase member. But this is an error, because Database is not public and is not accessible outside the library.

One choice is to declare Database as public

public class Database
{
}

public class BaseClass
{
     protected internal Database DtBase(...) {}
}


protected AND internalprotected internalthis discussion