我正在尝试使用插入查询(访问是数据库程序)但是我收到如下错误:
System.Data.OledDb.OleDbException (0x800004005): Operation must use an updateable query.
这是在我创建了一个.msi文件并安装它之后(它在Visual Studio中调试/运行时工作正常)。删除查询也不起作用,也不更新(只是选择查询)。当我尝试删除时,收到错误消息“无法从指定的表中删除”)。 (这是完整的异常消息:http://imgur.com/BSuh0nS)
以下是处理此
的两种方法的代码public void InsertData()
{
dbc.Open();
using (dbCmd = new OleDbCommand("INSERT INTO members (household_head, birthday, phone, email, address, status, spouse, spouse_birthday, spouse_phone, spouse_email, " +
"anniversary, spouse_status, child1, child1_birthday, child1_email, " +
"child2, child2_birthday, child2_email, child3, child3_birthday, child3_email, child4, child4_birthday, child4_email, child5, child5_birthday, child5_email," +
"child6, child6_birthday, child6_email, child7, child7_birthday, child7_email) " +
"VALUES (@txtBox_householdHead, @txtBox_householdHeadBirthday, @txtBox_householdHeadPhone, @txtBox_householdHeadEmail, @txtBox_householdHeadAddress, @txtBox_householdHeadStatus, " +
"@txtBox_spouse, @txtBox_spouseBirthday, @txtBox_spousePhone, @txtBox_spouseEmail, @txtBox_Anniversary, @txtBox_spouseStatus, " +
"@txtBox_child1, @txtBox_child1Birthday, @txtBox_child1Email, " +
"@txtBox_child2, @txtBox_child2Birthday, @txtBox_child2Email, @txtBox_child3, @txtBox_child3Birthday, @txtBox_child3Email, @txtBox_child4, @txtBox_child4Birthday, @txtBox_child4Email, " +
"@txtBox_child5, @txtBox_child5Birthday, @txtBox_child5Email, @txtBox_child6, @txtBox_child6Birthday, @txtBox_child6Email, @txtBox_child7, @txtBox_child7Birthday, @txtBox_child7Email)", dbc))
{
try
{
InsertDBParameters(ref dbCmd);
dbCmd.ExecuteNonQuery();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.ToString());
return;
}
}
MessageBox.Show("Record inserted.");
ClearAll(this);
dbc.Close();
}
和InsertDBParameters方法:
private void InsertDBParameters(ref OleDbCommand cmd)
{
foreach (Control c in Controls)
{
if (c is TextBox)
{
listOfTextboxes.Add(new KeyValuePair<string, string>(((TextBox)c).Name, ((TextBox)c).Text));
}
}
for (int i = 0; i < listOfTextboxes.Count; i++)
{
cmd.Parameters.AddWithValue(String.Format("@{0}", listOfTextboxes[i].Key.ToString()), listOfTextboxes[i].Value);
}
}
任何帮助将不胜感激,
谢谢!
我想象它必须是我迄今为止所研究的许可事物,但我不确定。这是我的连接字符串,如果它也有帮助:
OleDbConnection db = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\qbcdb.mdb");