什么是“缺少 SQL 属性”?这里?

发布于 2024-12-18 13:14:07 字数 470 浏览 2 评论 0原文

尝试执行代码时:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扛起拖把扫天下 2024-12-25 13:14:07

您在通过 rsnome.SQL.Text := ... 设置 SQL 之前调用 rsnome.Open

You're calling rsnome.Open before setting the SQL by rsnome.SQL.Text := ....

染火枫林 2024-12-25 13:14:07

我认为您根本不想使用 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

ゃ懵逼小萝莉 2024-12-25 13:14:07

你有几个错误。您在分配该 SQL 之前调用 Open(并且不需要这样做)。

您正在尝试设置一个参数值,但尚未创建要接受的参数。 (顺便说一句,我会让 ID 也是一个参数,这样你就可以用它来更新多个人的名字。)

你没有处理确保在出现错误的情况下清理事情(给出你发布的代码)肯定会有)。

您正在使用 Post,这对于 SQL 数据库来说不是必需的。

尝试这样的事情:

function TDBClass.addNome(nome: String): String;
var
  rsnome: TADOQuery;
begin
  rsnome := TADOQuery.Create(nil);
  try
    rsnome.Connection := connection;
    rsnome.SQL.Clear;
    rsnome.SQL.Text:='UPDATE enroll SET nome = :nome where id ="1"';
    rsnome.Parameters.ParamByName('nome').Value:= nome;
    rsnome.ExecSQL;
    rsnome.Close();
  finally
    rsnome.Free();
  end;
end;

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:

function TDBClass.addNome(nome: String): String;
var
  rsnome: TADOQuery;
begin
  rsnome := TADOQuery.Create(nil);
  try
    rsnome.Connection := connection;
    rsnome.SQL.Clear;
    rsnome.SQL.Text:='UPDATE enroll SET nome = :nome where id ="1"';
    rsnome.Parameters.ParamByName('nome').Value:= nome;
    rsnome.ExecSQL;
    rsnome.Close();
  finally
    rsnome.Free();
  end;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文