How could i select every record from table by TMyQuery?

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
timli
Posts: 2
Joined: Fri 01 Oct 2010 09:18

How could i select every record from table by TMyQuery?

Post by timli » Sat 19 Feb 2011 04:49

Hi all:
I have a "customer" table which have two fileds("id" and "phone").
The "id" field is auto_increment, and some records is deleted.So the table will look like this(id=1, 2, 4, 5, 7, 8 ) The records(ID=3 and 6) are deleted. How could i sequentially fetch every records without error?

.......................................................................................
MyQuery1->SQL->Clear();
MyQuery1->SQL->Add("SELECT * FROM customer");
MyQuery1->Execute();

RecCount = MyQuery1->RecordCount; //RecCount=6
for(i=1; iSQL->Clear();
MyQuery1->SQL->Add("SELECT * FROM customer WHERE id = :ID");
MyQuery1->ParamByName("ID")->AsInteger = i ;
ShowMessage(MyQuery1->FieldByName("phone")->AsString);
}

Thanks a lot

Justmade
Posts: 108
Joined: Sat 16 Aug 2008 03:51

Post by Justmade » Mon 21 Feb 2011 01:29

I myself use delphi rather than C++ but the logic is the same

MyQuery1.SQL.Text := 'SELECT * FROM customer';
MyQuery1.Active := True;
While not MyQuery1.Eof do
begin
ShowMessage(MyQuery1.FieldByName("phone").AsString;
MyQuery1.Next;
end;

All kinds of dataset can work like this so your might read some database related materials for more information.

AndreyZ

Post by AndreyZ » Mon 21 Feb 2011 09:23

Hello,

Justmade, thank you for your help.
To timli: You can use the solution Justmade offered.

timli
Posts: 2
Joined: Fri 01 Oct 2010 09:18

Re: How could i select every record from table by TMyQuery?

Post by timli » Tue 22 Feb 2011 08:19

It's work!

Thanks you!

AndreyZ

Post by AndreyZ » Tue 22 Feb 2011 09:55

Feel free to contact us if you have any further questions about MyDAC.

Post Reply