我试图使用以下方式更新访问数据库;ExecuteNonQuery不更新Access数据库
if(count > 0)
{
sqlQuery = "UPDATE facial_user SET facial_1=? WHERE username=?;";
using (OleDbCommand com2 = new OleDbCommand(sqlQuery, dbConnection))
{
sqlCommand.Parameters.AddWithValue("@facial_1", engine.imageToBase64String(new Bitmap(pictureBox.Image, new Size(pictureBox.Width/10, pictureBox.Height/10))));
sqlCommand.Parameters.AddWithValue("@username", userTextBox.Text);
sqlCommand.ExecuteNonQuery();
}
}
else
{
sqlQuery = "INSERT INTO facial_user(id, username, facial_1) VALUES(@id, @username, @facial_1);";
using (OleDbCommand com2 = new OleDbCommand(sqlQuery, dbConnection))
{
sqlCommand.Parameters.AddWithValue("@id", (dataSet.Tables[0].Rows.Count + 1).ToString());
sqlCommand.Parameters.AddWithValue("@username", userTextBox.Text);
sqlCommand.Parameters.AddWithValue("@facial_1", engine.imageToBase64String(new Bitmap(pictureBox.Image, new Size(pictureBox.Width, pictureBox.Height))));
sqlCommand.ExecuteNonQuery();
}
}
我能够输入两个条件没有问题,并退出它们没有错误。但是,在关闭dbconnection后,我的数据库文件没有反映出这些更改。
请指教。
您是否检查过您尝试更新的表中存在的用户名? – Venkatesh
如果您确定'Update'块被执行,唯一的问题可能是'UserName'与您的参数不匹配。 – BendEg
允许我详细说明我的问题,我首先必须读取db并检查是否存在记录。如果是,则计数> 0,并用更新更新该特定记录,否则计数= 0并插入新记录。我的程序能够确定哪些条件运行,所以我很确定我正在正确读取我的数据库。我只是不明白为什么我不能做出改变。 :( – jazy1992