如何获取 SQL 查询的结果?
使用 Delphi 2010,我使用 TSQLQuery 和 TSQLConnection 连接到远程 MySQL 服务器。我使用了如下 SQL 查询:
SQLQuery1.SQL.Text := 'SELECT * FROM registered WHERE email="'+email+'" and login_pass="'+password+'"';
SQLQuery1.Open; // Open sql connection
我应该如何列出或显示此查询选择的数据?
当我输入时,
SQLQuery1['who']; // The resault is : James Kan
我认为它正在显示列表中的最后一项。但我想显示每个项目,就像使用 PHP 中的 foreach 循环一样。例如,我如何为每个项目创建一个 TLabel?
Using Delphi 2010, I have used TSQLQuery and TSQLConnection to connect to a remote MySQL server. I have used an SQL query as follows:
SQLQuery1.SQL.Text := 'SELECT * FROM registered WHERE email="'+email+'" and login_pass="'+password+'"';
SQLQuery1.Open; // Open sql connection
What should I do to list or display the data selected by this query?
When I type
SQLQuery1['who']; // The resault is : James Kan
I think it is displaying the very last item in the list. But I want to display each item, as I could with the foreach loop in PHP. How could I create, for example, a TLabel for each item?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需迭代结果集即可
You just iterate over the resultset like
您可以使用 TDBGrid 来非常整齐地显示结果。您需要一个通过数据源的 DataSet 属性链接到您的查询的数据源。然后,DBGrid 通过 DBGrid 的 DataSource 属性链接到数据源。
You can use a TDBGrid to display the results quite neatly. You need a datasource which links to your query via the DataSet property of the datasource. Then the DBGrid links to the dataSource via the DataSource Property of the DBGrid.