JeanBonbeurre
JeanBonbeurre

Reputation: 3

No value given for one or more of the required parameters c#

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 !

Upvotes: 0

Views: 230

Answers (1)

Soner Gönül
Soner Gönül

Reputation: 98750

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.

Upvotes: 1

Related Questions