插入记录访问MDB与OleDB

本文关键字:OleDB MDB 访问 记录 插入 | 更新日期: 2023-09-27 18:10:42

为什么会这样?这一次简短而简单。哦,我正在连接到MDB文件(2007 Access)。

代码:

public bool insertRecord(int SR_Number, string Serial_Number, string Model_Number, bool Chargeable, bool Priority, bool Rollback)
    {
        string cmdStr = "INSERT INTO Recovery_CD_Orders ([SR_Number], [Serial_Number], [Model_Number], [Chargeable], [Priority], [Agent_placing_order], [Rollback_reqd]) Values (@SR_Number, @Serial_Number, @Model_Number, @Chargeable, @Priority, @Agent_Placing_Order, @Rollback)";
        OleDbCommand cmd = new OleDbCommand(cmdStr, thisCon);
        cmd.Parameters.AddWithValue("SR_Number", SR_Number);
        cmd.Parameters.AddWithValue("Serial_Number", Serial_Number);
        cmd.Parameters.AddWithValue("Model_Number", Model_Number);
        cmd.Parameters.AddWithValue("Agent_Placing_Order", Environment.UserName);
        cmd.Parameters.AddWithValue("Chargeable", Chargeable);
        cmd.Parameters.AddWithValue("Priority", Priority);
        cmd.Parameters.AddWithValue("Rollback", Rollback);
        cmd.Connection.Open();
        cmd.ExecuteNonQuery();
        cmd.Connection.Close();
        cmd.Dispose();
        return true;
    }
错误:

Data type mismatch in criteria expression.
表布局:

SR_Number: Number
Serial_Number: Text
Model_Number: Text
Agent_Placing_Order: Text
Chargeable: Yes/No
Priority: Yes/No
Rollback: Yes/No

插入记录访问MDB与OleDB

很难从问题中看出。我怀疑问题出在AddWithValue类型推断上。最好的办法是以旧式的方式显式声明类型,因为这将告诉访问使用什么。