C#/accdb:出现错误“操作必须使用可更新的查询". [英] C# / accdb: Getting error "Operation must use an updateable query."

查看:44
本文介绍了C#/accdb:出现错误“操作必须使用可更新的查询".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 C# 编写一个连接到 MS Access 数据库 (.accdb) 的应用程序.该应用程序将由多个工作人员使用,并且每个工作人员都会不时连接到数据库 - 以刷新他们的状态(刷新登录时间).

I'm writing an application in C# which connects to an MS Access database (.accdb). The application will be used by several workers and each of them will get connected to the db from time to time - to refresh their presence (refresh the sign-in time).

连接到同一个数据库的所有其他功能似乎都可以正常工作,但这个功能不行.由于某种原因,我收到以下错误,它说问题出在我的 ExecuteNonQuery() 所在的行中.命令文本由字符串 myUpdateNonquery 定义.

All other functions which connect to the same database seem to work fine but this one doesn't. I'm getting the below error for some reason and it says the problem is in the line where my ExecuteNonQuery() is. The command text is defined with the string myUpdateNonquery.

System.Data.OleDb.OleDbException (0x80004005): Operation must use an updateable query.

功能:

public Boolean RefreshSignIn()
{
  Boolean successful = false;
  lock(dbLock)
  {
    try
    {
      string myConnectionString = connectionType + primarydbPath;
      OleDbConnection myConnection = new OleDbConnection(myConnectionString);
      string myUpdateNonquery = "UPDATE AgentSignIn SET signInTime = NOW() WHERE agentName = @p1";
      using(myConnection)
      {
        OleDbCommand myCommand = new OleDbCommand(myUpdateNonquery, myConnection);
        using(myCommand)
        {
          myCommand.Parameters.Add("@p1", OleDbType.Char).Value = appSettings.mynick;

          myConnection.Open();
          int updatedRows = myCommand.ExecuteNonQuery();
          if (updatedRows>0) {successful = true;}
        }
      }
    }
    catch(System.Exception ex)
    {
      MessageBox.Show("Error! Failed to keep you signed in to the database!\n\n"+ex.ToString());
    }
  }
  return successful;
}

推荐答案

SQL 看起来不错.这似乎是一个权限问题,下面的文章概述了如何解决此问题:

The SQL looks fine. It seems to be a permission issue, the article below outlines how to fix this issue:

http://www.mikesdotnetting.com/Article/74/Solving-the-Operation-Must-Use-An-Updateable-Query-error

这篇关于C#/accdb:出现错误“操作必须使用可更新的查询".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆