CS0051: Inconsistent access
Hello, im currently working on an aircraft Database to store all my photos. Today I wanted to implement an USC for all the airlines. Everytime I set create a new airline I want it to create a new USC with a new airline, kinda like pokemom cards, but in the USC class it says following error: CS0051 Inconsistent access: Parameter type "MySQL.AirlineData" is less accessible than method "AirlineField_UC. SetAirlineData(MySQL.AirlineData)"
MySQL.cs (Got all SQL querys)
public class AirlineData
{
public string Name { get; set; }
public string ICAO { get; set; }
public string IATA { get; set; }
public string Callsign { get; set; }
public string Country { get; set; }
public string MainHub { get; set; }
public DateTime Founded { get; set; }
}
public List<AirlineData> getAirlines()
{
List<AirlineData> airlines = new List<AirlineData>();
try
{
string getAirlines = "SELECT * FROM airline;";
MySqlCommand cmdGetAirlines = new MySqlCommand(getAirlines, con);
openConnection();
using (MySqlDataReader reader = cmdGetAirlines.ExecuteReader())
{
while (reader.Read())
{
AirlineData airline = new AirlineData
{
Name = reader.GetString("name"),
ICAO = reader.GetString("icao"),
IATA = reader.GetString("iata"),
Callsign = reader.GetString("callsign"),
Country = reader.GetString("country"),
MainHub = reader.GetString("mainHub"),
Founded = reader.GetDateTime("founded")
};
airlines.Add(airline);
}
}
closeConnection();
}
catch (Exception ex)
{
MessageBox.Show("Error loading airlines: " + ex.Message);
}
return airlines;
}
12 Replies
AirlineData
needs to be public
if it's to be returned from a public
method
Ah, wait, it's not
Where's SetAirlineData
method?Airlines.cs (Form that needs to contain all USC)
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using static AircraftDB.MySQL;
namespace AircraftDB
{
public partial class AirlineList : Form
{
private MySQL mySQL;
public AirlineList()
{
InitializeComponent();
mySQL = new MySQL();
LoadAirlinesIntoControl();
}
private void btnAddAirline_Click(object sender, EventArgs e)
{
AddAirline addAirline = new AddAirline();
addAirline.Show();
}
public void LoadAirlinesIntoControl()
{
List<AirlineData> airlines = mySQL.getAirlines(); foreach (var airline in airlines) { var airlineControl = new AirlineField_UC(); airlineControl.SetAirlineData(airline); flowLayoutPanel.Controls.Add(airlineControl); } } } } AirlineField_UC (USC) using static AircraftDB.MySQL; namespace AircraftDB { public partial class AirlineField_UC : UserControl { public AirlineField_UC() { InitializeComponent(); } public void SetAirlineData(AirlineData airline) { lblAirlineName.Text = airline.Name; lblICAO.Text = airline.ICAO; lblIATA.Text = airline.IATA; lblCallsign.Text = airline.Callsign; lblCountry.Text = airline.Country; lblHeadquater.Text = airline.MainHub; lblFounded.Text = airline.Founded.ToShortDateString(); } } }
List<AirlineData> airlines = mySQL.getAirlines(); foreach (var airline in airlines) { var airlineControl = new AirlineField_UC(); airlineControl.SetAirlineData(airline); flowLayoutPanel.Controls.Add(airlineControl); } } } } AirlineField_UC (USC) using static AircraftDB.MySQL; namespace AircraftDB { public partial class AirlineField_UC : UserControl { public AirlineField_UC() { InitializeComponent(); } public void SetAirlineData(AirlineData airline) { lblAirlineName.Text = airline.Name; lblICAO.Text = airline.ICAO; lblIATA.Text = airline.IATA; lblCallsign.Text = airline.Callsign; lblCountry.Text = airline.Country; lblHeadquater.Text = airline.MainHub; lblFounded.Text = airline.Founded.ToShortDateString(); } } }
Weird, it should work
Are you using Visual Studio?
Yes
Is it because I didnt put the USC on the Form itself, there Im getting en error also xD
I wonder if the program maybe fails to compile and runs some old version that had the class as
internal
or somethingThe MySQL.cs is internat indeed, but the Method is public, is that the error?
Could be
Yeah,
AirlineList
is public
And I assume AirlineData
is a nested class of the internal MySql
class?
If so then yeah, that would do itI put the class on public and now it works
But i never got a problem with that and I did other querys too
Did those other queries also use classes nested in other
internal
classes?no
So I have to put the entire class on public or is there a better way to do it, I always instanced the MySQL class in the other ones and accesses it via mySQL.MethodName
You can access more accessible things from less accessible ones, but not the other way around
Okay, now its working, thank you