插入记录访问MDB与OleDB

时间:2011-10-06 23:49:20

标签: c# oledb jet

为什么会这样? :-S这一次简短而简单。哦,我正在连接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

1 个答案:

答案 0 :(得分:0)

很难说出问题中的内容。我怀疑问题是AddWithValue类型推断。您最好的选择是以旧式方式明确声明类型,因为这将告诉访问使用的内容。