我在C#中创建了一个程序,现在我想在Access数据库中更新一个布尔值。此布尔值将始终更新为false
。我绝对尝试过一切,我的价值没有变化。请帮忙。
这是我的代码:
[In mail]列是我的布尔值。我在Access中尝试了这个查询,它在那里工作得很好。
String query = "UPDATE Ontwikkeldossier SET Ontwikkeldossier.[In mail] = @fals WHERE (((Ontwikkeldossier.[OntwikkeldossierID])=@ontwikkeldossierid));";
using(OleDbConnection conn = new OleDbConnection(connstring))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(query, conn);
cmd.Parameters.Add("@fals", OleDbType.Boolean, 1, "[In mail]").Value = false;
cmd.Parameters.Add("@ontwikkeldossierid", OleDbType.Numeric).Value = Convert.ToInt32(newrow.Cells[0].Value.ToString());
cmd.ExecuteNonQuery();
}
提前致谢。
答案 0 :(得分:1)
updateCmd.Parameters.Add("@3", OleDbType.Boolean).Value = "true";
这对我有用! Access中有“是/否”列。更新命令是:
OleDbCommand updateCmd = new OleDbCommand("UPDATE email SET server = @1, port = @2, ssl = @3, utilizator = @4, parola = @5, subiect = @6, email = @7 WHERE ID = @8", connection);
答案 1 :(得分:0)
应该这样:
cmd.Parameters.Add("@fals", OleDbType.Boolean, 1, "[In mail]").Value = false;
取而代之的是:
cmd.Parameters.Add("@fals", OleDbType.Boolean).Value = false; //or zero, since it's an object, the DB might care...
来源是个问题吗?如果您要提供该值,为什么还需要值的来源?
当然,因为你的总是为假,你可以简单地改变查询并完全取消参数:
String query = "UPDATE Ontwikkeldossier SET Ontwikkeldossier.[In mail] = 0 WHERE (((Ontwikkeldossier.[OntwikkeldossierID])=@ontwikkeldossierid));";
答案 2 :(得分:0)
对于它的价值,我只是测试了以下代码,它对我有用:
using (var conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\__tmp\testData.accdb;"))
{
conn.Open();
using (var cmd = new OleDbCommand(
"UPDATE Ontwikkeldossier SET [In mail]=? WHERE OntwikkeldossierID=?",
conn))
{
cmd.Parameters.AddWithValue("?", false);
cmd.Parameters.AddWithValue("?", 1);
cmd.ExecuteNonQuery();
}
conn.Close();
}