How can I get results from query?

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
simveck
Posts: 1
Joined: Thu 31 May 2007 15:12

How can I get results from query?

Post by simveck » Thu 31 May 2007 15:17

How can I get results from query?
everything is OK with insert or remove, but when I want to get records from database I don't know how

TStrings *String;
MyQuery1->SQL->Add("select rating from ratings;");
MyQuery1->Execute();

AnsiString str = MyQuery1->GetDetailLinkFields(String,"rating","ratings");

or something i do wrong, I want to get results from database when i use select

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Re: How can I get results from query?

Post by eduardosic » Fri 01 Jun 2007 00:18

simveck wrote:How can I get results from query?
everything is OK with insert or remove, but when I want to get records from database I don't know how

TStrings *String;
MyQuery1->SQL->Add("select rating from ratings;");
MyQuery1->Execute();

AnsiString str = MyQuery1->GetDetailLinkFields(String,"rating","ratings");

or something i do wrong, I want to get results from database when i use select
MyQuery1->SQL->Add("select rating from ratings;");
MyQuery1->Execute();
Str = MyQuery1->FieldByName( 'FieldName' ).AsString;

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Fri 01 Jun 2007 07:10

This question concerns common issues of using TDataSet. You can read more about this in the Delphi help.
In your case you can use something like this:

Code: Select all

 AnsiString str = MyQuery1->FieldByName("rating")->AsString; 
Use TDataSet->Next to scroll to the next record in the recordset.

Post Reply