need help for my first simple query

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
07000
Posts: 2
Joined: Sat 05 Jul 2008 08:17

need help for my first simple query

Post by 07000 » Sat 05 Jul 2008 09:19

Hello,
years ago I programmed many things with Delphi 3. Now I have to build a programm which can interact (SELECT, INSERT, UPDATE, DELETE) with an MySQL-Database. I've learned, that the Borland components are not the best way to do this and so I found the "Data Acces Components for MySQL".

I studied the forum and learnd that I need the following components to start working:

"Following components are enough to get browsable and editable recordset:
1) MyConnection
2) MyTable or MyQuery
3) DataSource
4) DBGrid and DBNavigator "

...but which properties must I configure, so that this four components work together.

I use the "CodeGear™ RAD Studio 2007 Version 11.0.2902.10471" as a four weeks trial-version and the trial-version of the DAC-components.
As MySQL-Server I use a XAMPP-installation which definitly works fine.

I'm looking forward to a few hints so that I can start programming until the trialperiod ends. If I can't handle this MySQL-Querys until then I will skip the projekt.

Thanks!
Marcus

07000
Posts: 2
Joined: Sat 05 Jul 2008 08:17

Re: need help for my first simple query

Post by 07000 » Sat 05 Jul 2008 09:41

I clicked here and there and now it "works" (for SELECT). I can see the results of my query in the DBGrid.

But now I want to use the content of the DBGrid in variables to use it with my programm...
How to do this?

Example: "SELESCT count(*) FROM `workers`" will give me on cell with the value 77... How can I display the result in a statusbar (simple.text-option)?

Thanks!
Marcus

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

Post by Antaeus » Mon 07 Jul 2008 07:14

You can access field values of a dataset in this way:

Code: Select all

var
  s: string;
 begin
   MyQuery1.SQL.Text := 'SELECT count(*) FROM workers'
   MyQuery1.Open;
   s := MyQuery1.Fields[0].AsString;
   ShowMessage(s);
Or in this way:

Code: Select all

var
  s: string;
 begin
   MyQuery1.SQL.Text := 'SELECT count(*) as cnt FROM workers'
   MyQuery1.Open;
   s := MyQuery1.FieldByName('cnt').AsString;
   ShowMessage(s);
For more information see the description of the TDataSet class in the Delphi help.

Post Reply