插入记录 使用 OleDB 访问 MDB
为什么会出现这种情况? :-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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难从问题中提出的内容看出。我怀疑问题出在 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.