C
C#2mo ago
PANZER234425

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
Angius
Angius2mo ago
AirlineData needs to be public if it's to be returned from a public method Ah, wait, it's not Where's SetAirlineData method?
PANZER234425
PANZER2344252mo ago
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(); } } }
Angius
Angius2mo ago
Weird, it should work Are you using Visual Studio?
PANZER234425
PANZER2344252mo ago
Yes Is it because I didnt put the USC on the Form itself, there Im getting en error also xD
Angius
Angius2mo ago
I wonder if the program maybe fails to compile and runs some old version that had the class as internal or something
PANZER234425
PANZER2344252mo ago
The MySQL.cs is internat indeed, but the Method is public, is that the error?
Angius
Angius2mo ago
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 it
PANZER234425
PANZER2344252mo ago
I put the class on public and now it works But i never got a problem with that and I did other querys too
Angius
Angius2mo ago
Did those other queries also use classes nested in other internal classes?
PANZER234425
PANZER2344252mo ago
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
Angius
Angius2mo ago
You can access more accessible things from less accessible ones, but not the other way around
PANZER234425
PANZER2344252mo ago
Okay, now its working, thank you
Want results from more Discord servers?
Add your server