什么是“缺少 SQL 属性”?这里?
尝试执行代码时:
function TDBClass.addNome(nome: String): String;
var
rsnome: TADOQuery;
begin
rsnome := TADOQuery.Create(nil);
rsnome.Connection := connection;
rsnome.Open();
rsnome.SQL.Clear;
rsnome.SQL.Text:='UPDATE enroll SET nome = "test" where id ="1"';
rsnome.Parameters.ParamByName('nome').Value:= nome;
rsnome.ExecSQL;
rsnome.post();
rsnome.Close();
rsnome.Free();
end;
我收到错误消息“缺少 SQL 属性”。我哪里出错了?
提前致谢!
When trying to execute the code:
function TDBClass.addNome(nome: String): String;
var
rsnome: TADOQuery;
begin
rsnome := TADOQuery.Create(nil);
rsnome.Connection := connection;
rsnome.Open();
rsnome.SQL.Clear;
rsnome.SQL.Text:='UPDATE enroll SET nome = "test" where id ="1"';
rsnome.Parameters.ParamByName('nome').Value:= nome;
rsnome.ExecSQL;
rsnome.post();
rsnome.Close();
rsnome.Free();
end;
I'm receiving the error message "Missing SQL property". Where did I go wrong?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在通过
rsnome.SQL.Text := ...
设置 SQL 之前调用rsnome.Open
。You're calling
rsnome.Open
before setting the SQL byrsnome.SQL.Text := ...
.我认为您根本不想使用 Open,并且您使用的参数不正确。
即 SQL 中没有任何 :PARAM 占位符。我认为它应该是这样的:
rsnome.SQL.Text:='UPDATE enroll SET nome = :NOME where id = :ID';
请参阅此示例:
AdoQuery 使用参数时出错
I don't think you want to use Open at all, and you are using parameters incorrectly.
i.e. the SQL doesn't have any :PARAM placeholders in it. I think it should be something like:
rsnome.SQL.Text:='UPDATE enroll SET nome = :NOME where id = :ID';
See this example:
AdoQuery Error using parameters
你有几个错误。您在分配该 SQL 之前调用
Open
(并且不需要这样做)。您正在尝试设置一个参数值,但尚未创建要接受的参数。 (顺便说一句,我会让 ID 也是一个参数,这样你就可以用它来更新多个人的名字。)
你没有处理确保在出现错误的情况下清理事情(给出你发布的代码)肯定会有)。
您正在使用
Post
,这对于 SQL 数据库来说不是必需的。尝试这样的事情:
You have several errors. You're calling
Open
before you've assigned ths SQL (and without needing to do so).You're trying to set a parameter value you haven't created a parameter to accept. (BTW, I'd make ID also a parameter, so you can use this to update more than one person's name.)
You're not handling making sure that things get cleaned up in case there's an error (which given the code you posted there certainly will be).
You're using
Post
, which isn't necessary with an SQL database.Try something like this instead: