Click here to Skip to main content
15,923,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.

which line in the below code is wrong :

C#
public string Sele_count_dont_pay_ghest(string U_today)
       {
           string ret = string.Empty;
           string select_count_with_today = "SELECT COUNT(*) FROM ghesting WHERE (date_ghest <= ? )";
           OleDbParameter[] pp = new OleDbParameter[1];
           pp[0] = new OleDbParameter("date_ghest", OleDbType.Char);
           pp[0].Value = Convert.ToString(U_today);
          // a.Query_select_all_command(select_count_with_today);
         ret =  a.Query_Select_ExecuteScaler(select_count_with_today).ToString();

         return ret;

       }


I have following error :
No value given for one or more required parameters.

thanks.
Posted

1 solution

You never added the parameter to the command Object.

Do something like this:
C#
string select_count_with_today = "SELECT COUNT(*) FROM ghesting WHERE (date_ghest <= ? )";
cmd.Parameters.AddWithValue("@date", U_today.ToString();


using .Parameters.AddWithValue() means you can add the parameter in one line of code and is much easier to read.
 
Share this answer
 
v2
Comments
Richard Deeming 12-Mar-15 9:55am    
Almost perfect, except that OleDbCommand doesn't use named parameters. :)
ZurdoDev 12-Mar-15 10:02am    
Thanks. I updated it and put it back to a question mark. It appears that it's just the order you add parameters in that is important.
bernova 12-Mar-15 11:13am    
thanks . but i have same error
when remove WHERE statement , the query run correctly.
ZurdoDev 12-Mar-15 11:30am    
Show your code then.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900