0
string queryString = "SELECT SUM(skupaj_kalorij)as Skupaj_Kalorij  "
                    + "FROM (obroki_save LEFT JOIN users ON obroki_save.ID_uporabnika=users.ID)"
                    + "WHERE users.ID= " + a.ToString() + " AND obroki_save.datum =?";


using (OleDbCommand cmd = new OleDbCommand(queryString,database))                                    
{
    cmd.Parameters.Add("@datum", OleDbType.Char).Value = DateTime.Now.ToShortDateString();    
}

Why doesn't the parameter datum get the date value? (the value of at least one complex parameter has not been determined )

0

2 Answers 2

4

From the docs for OleDbCommand.Parameters

The OLE DB .NET Provider does not support named parameters for passing parameters to an SQL Statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used.

Try using the positional approach instead, basically.

6
  • Do you mean just like : Where datum=#"DateTime.Now()+"#";
    – Simon
    Jun 15, 2010 at 12:36
  • @Simon: No, I mean using a "?" placeholder, as described in the quoted paragraph. Read the linked documentation for a fuller example.
    – Jon Skeet
    Jun 15, 2010 at 12:37
  • Ok... But i can't make it work. How do i use that in my case (give the parameter the date value and compare it to the date in the database ?
    – Simon
    Jun 15, 2010 at 13:18
  • @Simon: Just change the SQL statement to have "?" instead of @datum and I'd expect it to work. I don't know whether you need to remove the name from the Add call as well...
    – Jon Skeet
    Jun 15, 2010 at 13:51
  • if it would be that easy... i did that before i asked. I still get the same error ( no value given to at least one parameter(smt. like that))
    – Simon
    Jun 15, 2010 at 13:59
0

If that's cut straight from your code then it might be giving an error because it needs a space in your queryString before the WHERE clause.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.