操作必须使用可更新的查询。 [英] Operation must use an updateable query.

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

问题描述

亲爱的所有人,当我更新msaccess文件时出现错误:





操作必须使用可更新的查询。



代码是

  string  strSQL =  更新帐户集OBAL_AM =(从帐户中选择前1个OBAL_AM,其中Acct_Cd =' + TextBox1.Text +  '和Code_No =' + brcod +  ')其中Acct_Cd =' + TextBox2.Text +  '和Code_No =' + brcod +  '; 
OleDbCommand cmd = new OleDbCommand(strSQL,myConn);
myConn.Open();
cmd.ExecuteNonQuery(); myConn.Close();

解决方案

看到这篇文章 http://www.mikesdotnetting.com/Article/74/Solving-the-Operation-Must-Use-An-Updateable-Query -error [ ^ ]


错误消息非常清楚,如果您不完全理解它,您应该真正阅读关系数据库和ADO。 NET几乎从头开始,只了解基本的想法。



如果您使用的是 ExecuteNonQuery ,则意味着您的SQL语句应该修改数据库中的某些数据,但是您的 select 语句,即纯查询。不是那么明显:你正在使用带有查询的 ExecuteNonQuery



有了查询,你应该使用 ExecuteReader ExecuteScalar ,以获取查询结果:http://msdn.microsoft.com/en-us/library/system.data.oledb .oledbcommand%28v = vs.110%29.aspx [ ^ ]。



-SA

Dear All, When i update msaccess file the error comes:


Operation must use an updateable query.

code is

string strSQL = "Update Account set OBAL_AM=(select top 1 OBAL_AM from  Account where Acct_Cd='" + TextBox1.Text + "' and Code_No='" + brcod + "') where  Acct_Cd='" + TextBox2.Text + "'  and Code_No='" + brcod + "'";
            OleDbCommand cmd = new OleDbCommand(strSQL, myConn);
            myConn.Open();
            cmd.ExecuteNonQuery(); myConn.Close();

解决方案

See this post http://www.mikesdotnetting.com/Article/74/Solving-the-Operation-Must-Use-An-Updateable-Query-error[^]


The error message is so clear that, if you don't fully understand it, you should really read on relational databases and ADO.NET pretty much from scratch, to understand just the basic ideas.

If you are using ExecuteNonQuery, it means that your SQL statement is supposed to modify some data in the database, but your is a select statement, that is, a pure query. Isn't that obvious: you are using ExecuteNonQuery with a query.

With a query, you should use ExecuteReader or ExecuteScalar, to have something to obtain the query results: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand%28v=vs.110%29.aspx[^].

—SA


这篇关于操作必须使用可更新的查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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