插入记录 使用 OleDB 访问 MDB

发布于 2024-12-08 17:36:19 字数 1439 浏览 0 评论 0原文

为什么会出现这种情况? :-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

Why does this happen? :-S Short and simple this time round. Oh, I'm connecting to an MDB file (2007 Access).

Code:

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;
    }

Error:

Data type mismatch in criteria expression.

Table Layout:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回心转意 2024-12-15 17:36:19

很难从问题中提出的内容看出。我怀疑问题出在 AddWithValue 类型推断上。最好的选择是以老式方式明确声明类型,因为这将告诉访问权限使用什么。

Hard to tell from what is presented in the question. I suspect the issue is with the AddWithValue type inference. Your best bet is to explicitly declare the types in old school fashion as that will tell access what to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文