【问题标题】:How to insert data into a MySQL table in MyQuery (Delphi)如何在 MyQuery (Delphi) 中将数据插入 MySQL 表
【发布时间】:2012-07-31 01:44:47
【问题描述】:

我正在通过建立用户注册应用程序进行 mysql 连接。我使用的是 Delphi 7。Myquery(MySQL 访问集)在添加用户信息时出现问题。

MyQuery1.SQL.Clear;
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (nick) VALUES ('+QuotedStr(DBEdit1.text)+')');
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (mail) VALUES ('+QuotedStr(DBEdit2.text)+')');
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (site) VALUES ('+QuotedStr(DBEdit3.text)+')');
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (pass) VALUES ('+QuotedStr(DBEdit4.text)+')');
MyQuery1.CachedUpdates:=True;
MyQuery1.Open;

错误消息: MyQuery1:未提供 SQL 语句。

注意: uyeler:成员表。

【问题讨论】:

    标签: mysql delphi delphi-7 mydac


    【解决方案1】:

    因为您没有填写 SQL 属性,而是使用了作为查询语句模板的 SQLInsert,所以引发了此消息。

    一些额外的提示

    1. 您必须使用Execute 方法,Open 方法适用于SELECT 语句。
    2. 使用单个插入句子,如

      INSERT INTO uyeler (nick,mail,site,pass) VALUES ('','','','')

    3. 尝试使用参数,而不是直接传递字符串值,这样可以避免sql注入攻击,提高性能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多