dbExpress如何显示查询结果? [英] dbExpress how to show result from query?

查看:52
本文介绍了dbExpress如何显示查询结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var
  Connection: TSQLConnection;
  SqlSet:TSQLDataSet;
begin
  Connection := TSQLConnection.Create(nil);
  SqlSet := TSQLDataSet.Create(nil);
  SqlSet.SQLConnection:=Connection;
  Connection.DriverName := 'MySQL';
  Connection.GetDriverFunc := 'getSQLDriverMYSQL';
  Connection.LibraryName := 'dbxmys.dll';
  Connection.VendorLib := 'libmysql.dll';
  Connection.LoginPrompt:=False;


  Connection.Params.Values['Database']:=('shadowxx1');
  Connection.Params.Values['User_Name']:=('shadowxx1');
  Connection.Params.Values['Password']:=('shadowxx1');
  Connection.Params.Values['HostName']:=('shadowxx1');
  Connection.Open;
  Connection.Connected:=True;

  SqlSet.CommandType:=ctQuery;
  SqlSet.CommandText:= 'SELECT VERSION()';
  SqlSet.ExecSQL;


  Connection.Close;
  Connection.Free;
  SqlSet.Free;
end;

代码正常工作,但是,如何显示查询结果或将其提取到网格中???我只是找不到这些信息,在ADO中就像这样

Code working , but , how to show result of query or extract it to the grid??? I simply dont find this information, in ADO it was smth like this

DataSrc := TDataSource.Create(Self);
DataSrc.DataSet := ADOQuery;
DataSrc.Enabled := true;
DBGrid1.DataSource := DataSrc;

如果有人可以,请举一些例子

If someone can - give some examples

像这样不起作用

推荐答案

您使用了错误的方法.在具有它的任何 TDataSet 后代中, ExecSQL 用于执行不返回任何结果集的查询,例如INSERT,UPDATE,DELETE或CREATE TABLE.例如,请参见 TSQLQuery.ExecSQL (强调我的)

You're using the wrong method. In any of the TDataSet descendants that have it, ExecSQL is for executing queries that return no result set, such as INSERT, UPDATE, DELETE, or CREATE TABLE. See, for instance, TSQLQuery.ExecSQL (emphasis mine)

执行一个查询,该查询不返回一组记录.

调用ExecSQL执行不返回记录集的SQL命令.此命令是查询,而不是SELECT查询,例如INSERT,UPDATE,DELETE或CREATE TABLE查询.

Call ExecSQL to execute an SQL command that does not return a set of records. This command is a query other than a SELECT query, such as an INSERT, UPDATE, DELETE, or CREATE TABLE query.

使用 TSQLQuery.Open 从SELECT返回行.像这样的东西应该可以工作(未经测试-我不使用MySQL或DBExpress):

Use TSQLQuery.Open to return rows from a SELECT. Something like this should work (untested - I don't use MySQL or DBExpress):

var
  Qry: TSQLQuery;
  VersionString: String;


  // Set up your connection as above, and open it

  Qry := TSQLQuery.Create(nil);
  Qry.SQLConnection := Connection;

  Qry.SQL.Text := 'SELECT VERSION() as DBVersion';
  Qry.Open;

  if not Qry.IsEmpty then
    VersionString := Qry.FieldByName('DBVersion').AsString
  else
    VersionString := 'No results found';
  Qry.Close;

有关更多信息(包括分步教程),请参见使用DBExpress组件,在Delphi docwiki上.(我链接的是针对当前Delphi版本的,但是自从引入DBExpress以来,其基本步骤是相同的​​.)

For more information (including step-by-step tutorials), see Using DBExpress Components at the Delphi docwiki. (The one I've linked is for the current Delphi version, but the basic steps for DBExpress are the same since it was introduced.)

如果您想在Delphi中使用DBExpress的基本视频教程,可以尝试 DBExpress数据Delphi中的访问组件-Delphi 101 .我没看过,但是它是由Delphi的制造商Embarcadero发布的.

If you want a basic video tutorial for using DBExpress in Delp you can try DBExpress Data Access Components in Delphi - Delphi 101. I haven't watched it, but it was posted by Embarcadero, the makers of Delphi.

这篇关于dbExpress如何显示查询结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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