Page 1 of 1

How could i select every record from table by TMyQuery?

Posted: Sat 19 Feb 2011 04:49
by timli
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

Posted: Mon 21 Feb 2011 01:29
by Justmade
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.

Posted: Mon 21 Feb 2011 09:23
by AndreyZ
Hello,

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

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

Posted: Tue 22 Feb 2011 08:19
by timli
It's work!

Thanks you!

Posted: Tue 22 Feb 2011 09:55
by AndreyZ
Feel free to contact us if you have any further questions about MyDAC.