Search code examples
c#ms-accessoledboledbcommand

MS-Access, OleDbCommand, Getting a "No value given for one or more required parameters"


I'm having trouble because I'm very rusty with using OleDb with Microsoft access. I add parameters to the command, and execute the query and I get "No value given for one or more required parameters."

void LoadPositions(string accountKey, IEnumerable<Positions> positions)
{
    OleDbCommand cmd1 = new OleDbCommand("delete from AccountPositions where BrokerAccountKey=?", conn, tran);
    cmd1.Parameters.Add("?", OleDbType.VarChar).Value = brokerAccountKey;
    cmd1.ExecuteNonQuery();
}

I'm at my wits' end... help somebody! Thanks in advance.


Solution

  • "delete * from AccountPositions where BrokerAccountKey=@variableName"
    

    I think you need to add the @ for your parameters if I remember correctly for access.

    It's not liking you using the ? for variable name. I just tried this out and it works fine.

    EDIT *

    Try defining your parameters a little different.

    cmd1.Parameters.AddWithValue("@variableName", txtSomeValue.text);
    

    Just make sure that txtSomeValue.text is the same value as what you have defined in the access db.

    If none of this works, then most likely "brokerAccountKey" is actually undefined when access is trying to commit the query.