简体   繁体   中英

Data type mismatch exception in Access query

I have the following code:

 public void GetParameterSelectionSet(int wire, int bond, string processProgramPath)
    {

        string connectionString = "Provider=Microsoft.JET.OLEDB.4.0;" + "data source=" + processProgramPath + ";";
        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            connection.Open();
            using (OleDbCommand command = new OleDbCommand("SELECT * " +
                                                        "FROM BONDS INNER JOIN WIRES on " +
                                                        "BONDS.WireID = WIRES.WireID " +
                                                        "WHERE (WIRES.OperationOrder =  '@WireOrder') AND" +
                                                        "(BONDS.OperationOrder = '@BondOrder')", connection))
            {
                command.Parameters.Add(new OleDbParameter("@WireOrder", OleDbType.Numeric));
                command.Parameters.Add(new OleDbParameter("@BondOrder", OleDbType.Numeric));
                command.Parameters["@WireOrder"].Value = wire;
                command.Parameters["@BondOrder"].Value = bond;


                var mytemp = command.ExecuteScalar();
            }
        }

    }

When I execute this query i get a "Data Type mismatch in criteria expression".

Both WIRES.OperationOrder and BONDS.OperationOrder are of type Numeric. So I am lost as to why this is failing.

Thanks in advance!

您在SELECT语句中的数字参数前后加上了引号,这是不正确的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM