J'ai un peu le même problème, j'ai une requête à laquel j'ajoute des paramètre, mais ça me lance l'exception : OleDbException : la variable "@Mandat" scalaire doit être déclarée.
Voici ma requête :
1 2 3 4 5
| SELECT TOP 5
MandatLot.man_id, MandatLot.imm_id
FROM mandat_lot AS MandatLot
WHERE MandatLot.man_id = @Mandat
AND MandatLot.imm_id = 68752 |
Mon code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| /* Connexion */
connexion = new OleDbConnection(paramConnexion);
/* Création de la requête */
commande = new OleDbCommand();
commande.Connection = connexion;
commande.CommandType = CommandType.Text;
commande.CommandText = requete;
/* Paramètres */
commande.Parameters.Add("@Mandat", mandat);
/* Exécution de la requête et récupération des données résultant */
DataSet donnees = new DataSet();
adapter = new OleDbDataAdapter();
adapter.SelectCommand = commande;
adapter.Fill(donnees, nomTable); |
Pour la partie /* Paramètres */ j'ai aussi essayé :
commande.Parameters.AddWithValue("@Mandat", mandat);
commande.Parameters.Add(new OleDbParameter("@Mandat", mandat));
et
1 2 3 4
| OleDbParameter param = commande.CreateParameter();
param.ParameterName = "Mandat";
param.Value = mandat;
commande.Parameters.Add(param); |
J'ai un peu tout essayer, du coup je ne sais plus trop quoi faire?
Partager