Im working on a app for my study. now i just started a app where i got a database with the soccer league's and the clubs etc. now i had a list with the club and the players now im trying to add in more league's then just 1. but i get this error when im doing the same thing then doing before. this is the code of the not working list:
public List<Competitie> GetAllCompetities()
{
List<Competitie> Competitie = new List<Competitie>();
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
string query = "Select * from competitie";
MySqlCommand selectallcompetitiecommand = new MySqlCommand(query, connection);
MySqlDataReader reader = selectallcompetitiecommand.ExecuteReader();
while (reader.Read())
{
Competitie comp = new Competitie();
comp.IdCompetitie = reader.GetInt32(0);
comp.NaamCompetitie = reader.GetString(1);
Competitie.Add(comp);
}
}
return Competitie;
}
and then this is the code of the clubs this do is working:
public List<Clubs> GetAllClubs(string selecteditem)
{ //Zorgt voor alle dingen van de tabel clubs.
List<Clubs> Clubs = new List<Clubs>();
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
string query = "Select * from databasevoetbal.clubs where competitie.naamcompetie = '" + selecteditem + "' and clubs.idcompetitie = competitie.idcompetitie";
MySqlCommand selectAllClubsCommand = new MySqlCommand(query, connection);
MySqlDataReader reader = selectAllClubsCommand.ExecuteReader();
while (reader.Read())
{
Clubs Club = new Clubs();
Club.idClubs = reader.GetInt32(0);
Club.NaamClubs = reader.GetString(1);
Club.aantalkampioenschappen = reader.GetInt32(2);
Club.opgericht = reader.GetInt32(3);
Club.idcompetitie = reader.GetInt32(4);
Clubs.Add(Club);
}
}
return Clubs;
}
It's the same code only the query in the club uses a selected item from a listbox but anybody knows why i get this error in the first list:
Error CS0050 Inconsistent accessibility: return type '
List<Competitie>
' is less accessible than method 'DatabaseManager.GetAllCompetities()
'
Code for the class:
class Competitie
{
public int IdCompetitie { get; set; }
public string NaamCompetitie { get; set; }
public override string ToString()
{
return string.Format("{0}", NaamCompetitie);
}
}
Competitie
class? And is itpublic
, or not? If not, then that might explain the error, because then there's a chance that code which can call the GetAllCompetities() method (because it'spublic
) cannot access the class which the method returns. And clearly that is not a logical situation – Orthiconusing
does. – Orthiconpublic class Competitie
. Otherwise it defaults to beinginternal
(i.e.accessible only within the assembly it's compiled into). As the error says, the class must be at least as accessible as the method which returns it – Orthiconusing
block. And beware the Sql injection vulnerability: use parameters rather than string concatenation. – Manoeuvre