Help to newbie with delphi & mysql & mydac data fetch

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
VBSensei
Posts: 1
Joined: Thu 19 Apr 2007 13:02

Help to newbie with delphi & mysql & mydac data fetch

Post by VBSensei » Thu 19 Apr 2007 13:17

Hi

I'm a old VB programmer, but now I have to move into Delphi, but it brings lots of problems, like converting old VB code into new delphi one. I have discovered many things by myself, but one thing with database handling is mystery, how it is done in Delphi with MyDac.

See, I have this old VB&ADO code that can access datatable fields by their name.
First I get some info -> rs.open "Select * from Table;"
Then I get access to that info -> var = rs![FieldAny]

but the point is, that I need to access that table by its name, not with some kind of index, because it is very ugly debug-show, if there is billion lines of code, and I add new field into table, then indexes may go wrong! DB 99% probably updates during program lifetime.

I want this kind of thing to work : ShowMessage(frmImport.MyQuery1.Fields['AnyField'].AsString);

Not THIS
ShowMessage(frmImport.MyQuery1.Fields[0].AsString);

All I have discovered this far, that I cannot call info with field name, but just with index... and that is not acceptable.

Can you help?

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

Post by Antaeus » Thu 19 Apr 2007 14:55

Try to use the FieldByName method. It can be used in this way:

Code: Select all

ShowMessage(frmImport.MyQuery1.FieldByName('AnyField').AsString); 

Post Reply