Hello. I couldn't think of any better name for the title.
To the point...
I have this database reader method, and In the while loop, where the liga[] is being populated, all its values are the last that is read from DB..
Clubs ID are from 1 - 10
Any suggestions?
private static bool readDatabase(ref string strError, Club[] liga)
{
bool blnRetVal = true;
Player player = new Player();
Club club = new Club();
string selectSQL = "SELECT * FROM Players";
string selectClub = "SELECT * FROM Clubs";
try
{
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
conn.Open();
using (OleDbDataReader rdr = (new OleDbCommand(selectClub, conn)).ExecuteReader())
{
while (rdr.Read()) // THIS IS WHERE THE PROBLEM STARTS
{
club.Id = int.Parse(rdr["IDclub"].ToString());
club.clubName = rdr["ClubName"].ToString().Trim();
club.Pld = int.Parse(rdr["Pld"].ToString());
club.W = int.Parse(rdr["W"].ToString());
club.D = int.Parse(rdr["D"].ToString());
club.L = int.Parse(rdr["L"].ToString());
club.Gf = int.Parse(rdr["Gf"].ToString());
club.Ga = int.Parse(rdr["Ga"].ToString());
club.Gd = int.Parse(rdr["Gd"].ToString());
club.Money = int.Parse(rdr["Money"].ToString());
liga[club.Id-1] = club;
}
rdr.Close();
}
using (OleDbDataReader rdr = (new OleDbCommand(selectSQL, conn)).ExecuteReader())
{
while (rdr.Read()) // Fill players
{
player.Name = rdr["name"].ToString().Trim();
player.Surname = rdr["surname"].ToString().Trim();
player.Position = rdr["position"].ToString().Trim();
player.Age = int.Parse(rdr["age"].ToString().Trim());
player.DaysInj = int.Parse(rdr["daysInj"].ToString().Trim());
player.ClubPlayingFor = int.Parse(rdr["Club"].ToString());
player.IdPlayer = int.Parse(rdr["IDplayer"].ToString());
player.Creativity = int.Parse(rdr["creativity"].ToString());
player.Shooting = int.Parse(rdr["shooting"].ToString());
player.Passing = int.Parse(rdr["creativity"].ToString());
player.Speed = int.Parse(rdr["speed"].ToString());
player.Jump = int.Parse(rdr["jump"].ToString());
player.Head = int.Parse(rdr["head"].ToString());
player.Defence = int.Parse(rdr["goalkeeping"].ToString());
player.Creativity = int.Parse(rdr["creativity"].ToString());
foreach (Club c in liga)
{
if (player.ClubPlayingFor == c.Id)
{
c.PlayersBL.Add(player);
}
}
}
rdr.Close();
}
conn.Close();
}
}
catch (Exception exc)
{
blnRetVal = false;
strError = exc.Message;
}
MessageBox.Show(strError.ToString());
return blnRetVal;
}