Simple sample to access database for beginner

I am a beginner in Delphi Programing, but i had experience in VB6. Can some one show me a sample of how to access the data in the database(Ms Access) by using both coding and component object.

Imagine the following situation:
Database: myProperty.mdb
SQL Query:
'Select * from tblVehicle where VehicleNo := myVehicleNo'
Table: tblVehicleNo
Column: VehicleNo, Type, color...

Can u show me using Query and other data control?
(Actualy i m not sure how to use the Borland Delphi 6.0 Interfaces to create the database object by using drag and drog. I am not sure wheter BDE or ADO is better and easier)
Who is Participating?
Create a new application and drop on an ADOConnection component.  In the connectionString property, click the'...' box.  This will let you specify connection properties for your Access database.  It's just like setting up an ODBC connection.

Now place an ADOQuery component on the form.  Go to it's Connection property and select ADOConnection1 (The connection you placed previously) from the drop down list.

Place a button on the form and double click it.  Put this code snippet in the code window that appears...

procedure TForm1.Button1Click(Sender: TObject);
  MyVehicleNo: String;
  MyVehicleNo := '1';

  ADOQuery1.SQL.Add('select * from tblVehicle where VehicleNo = ' + myVehicleNo);

  //Place code to look at results here...


You then need to enter some more code to do something with the data.  Either that or place a datasource and DBGrid on the form to view the results.

Hope that helps...
Is better to use ADO.
Bassically you need a ADO connection Component To conecct with Access Database.

AdoQuery or AdoStorProc

With AdoStorProc you build the query in Access and execute from Delphi.
you must use the Name of this query Name:Qr_xxxxx
and Active:True.

With AdoQuery, you must build in Delphi your SQL sentence.

Qr_Faltas.SQL.ADD('Select tb_employee.Name, tb_employee city');
Qr_Faltas.SQL.ADD('From Tb_Employee');
Qr_Faltas.SQL.ADD('Order by;);


Best Regards.

Dear cekcool

Free online database programming course for beginner Delphi developers. Focus on ADO techniques.

Learning DB programming with Delphi.

Best Regards

You could use Opus DirectAccess (  It's open source now and it's very fast.  BDE is easier but not as powerful or fast.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.