[C# ADO.NET] Nom de colonne introuvable
Bonjour,
J'effectue ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
//-- Requete --//
OleDbConnection Connexion = new OleDbConnection(this.Connexion.ConnectionString);
string requete = "Select EQ1.Nom as 'EquipeH', "+
"EQ2.Nom as 'EquipeA', "+
"tbMatchs.NumMatch as 'NumMatch', "+
"tbMatchs.Score as 'Score', "+
"tbMatchs.[Date] as 'Date' "+
"From tbEquipes as EQ1, tbEquipes as EQ2, tbMatchs, tbSaisons "+
"Where EQ1.IDEquipe=tbMatchs.IDEquipe1 And EQ2.IDEquipe=tbMatchs.IDEquipe2 And "+
"(tbMatchs.IDSaison = tbSaisons.IDSaison And tbSaisons.Creation = true) " +
"And NumMatch="+this.listBox1.Text.Substring(0,listBox1.Text.IndexOf(")"));
OleDbCommand cmd = new OleDbCommand(requete,Connexion);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"tbMatchs");
for(int i=0;i<ds.Tables["tbMatchs"].Columns.Count;i++)MessageBox.Show(ds.Tables["tbMatchs"].Columns[i].ColumnName);
//-- Label --//
this.lbSepare.Text=ds.Tables["tbMatchs"].Rows[0]["Score"].ToString();
this.lbJournee.Text=ds.Tables["tbMatchs"].Rows[0]["NumMatch"].ToString();
this.lbDate.Text=ds.Tables["tbMatchs"].Rows[0]["Date"].ToString(); |
Lors de la première affectation d'un string au lebel lbSepare, j'ai une exception me signifiant que le nom de la colonne Score n'existe pas.
Pourtant j'affiche un peu plus haut l'ensemble des noms de colonnes, et Score est bien présent... et ds.Tables["tbMatchs"].Rows.Count me renvoit bien une ligne...
Je ne vois pas trop où est mon erreur... si quelqu'un peut m'aider... Merci.