0

The above-mentioned exception is thrown by visual studio when I run the result of this code's compilation :

requete = @"select v.[*] from Visite v, Infirmière i where v.[code_inf] = i.[code_inf]" /* +
           " and i.[nom_inf]='" + nom + "'" +
           " and i.[prenom_inf]='"+prenom+"'"+
           " and v.[date_visite]=to_date('" + d.ToString().Substring(0, 10)+"','DD/MM/YYYY')" */
           ;
MessageBox.Show(requete);


OleDbCommand dbc = new OleDbCommand(requete, connec);

OleDbDataReader dr = dbc.ExecuteReader();

while(dr.Read())
{
    dgv_res.Rows.Add(dr.Read());
}

dgv_res is a datagridview component, and connec is an open connection.

I commented a part of my request to see if there was a SQL mistake in it but I really don't see what's wrong in the first line and I keep on getting this exception. I've checked the columns and tables names many times.

This

no value given for one or more of the required parameters

is thrown where I create the OleDbDataReader I think.

Thanks for reading !

  • Break it down until you find your problem. Does `SELECT * FROM Visite` work? – nvoigt Apr 27 '15 at 14:44
  • 1
    Sometimes this error can be thrown due to a syntax error in the query. Have you tried executing this statement in a SQL tool? Are any errors thrown, or does it execute correctly? – SWalters Apr 27 '15 at 14:45
  • Or add a parameter with value to your `OleDbCommand` and see where it's replacing exactly :) – Soner Gönül Apr 27 '15 at 14:51
  • "Select * from visite" does work, and I have my database as an mbd file so I'm not quite sure how to use requests on it – JeanBonbeurre Apr 27 '15 at 14:54

1 Answers1

1

AFAIK, you can't use [] with * and since OLE DB provider does not care named parameters, it may think this [*] is a parameter and expect a parameter value for it.

If everything is okey other than that, this should work;

@"select v.* from Visite v, Infirmière i where v.[code_inf] = i.[code_inf]"

With [*], database engine thinks you have a column name called * exactly, not all columns in v table.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364