0

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();
        }
    }
}
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
dhaJAY
  • 13
  • 3
  • Where is your class `Database`? What if you append `public class ` before the class definition? – Patrick Hofman May 03 '17 at 07:42
  • 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 May 03 '17 at 07:49
  • 2
    Please edit your question to include that code. – Patrick Hofman May 03 '17 at 07:50

1 Answers1

0

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(...) {}
}


It would be great if C# had a way of setting the accessibility to protected AND internal. But, it turns out you cannot do that. (protected internal does not mean what you might automatically think it means, see this discussion)
Community
  • 1
  • 1
Andrew Shepherd
  • 44,254
  • 30
  • 139
  • 205