Simon
Simon

Reputation: 73

Parameter has no value

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 )

Upvotes: 0

Views: 222

Answers (2)

MLT
MLT

Reputation: 514

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.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1499780

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.

Upvotes: 4

Related Questions