Solved

Simple sample to access database for beginner

Posted on 2002-05-12
4
249 Views
Last Modified: 2011-09-20
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)
0
Comment
Question by:cekcool
4 Comments
 
LVL 3

Expert Comment

by:marcoszorrilla
ID: 7005285
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.Close;
Qr_Faltas.SQL.Clear;
Qr_Faltas.SQL.ADD('Select tb_employee.Name, tb_employee city');
Qr_Faltas.SQL.ADD('From Tb_Employee');
Qr_Faltas.SQL.ADD('Order by Tb_Employee.name;);

Qr_Faltas.Open;

Best Regards.
Marcos

0
 
LVL 8

Expert Comment

by:Cesario
ID: 7005367
Dear cekcool

Free online database programming course for beginner Delphi developers. Focus on ADO techniques.
http://www.delphi.about.com/library/weekly/aa010101a.htm?PM=ss12_delphi

Learning DB programming with Delphi.
http://www.delphi.about.com/cs/dbbegin/index.htm

Best Regards

Cesario
0
 

Accepted Solution

by:
david-johnstone earned 50 total points
ID: 7005924
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);
var
  MyVehicleNo: String;
begin
  MyVehicleNo := '1';

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

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

  ADOQuery1.Close;
end;

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...
0
 
LVL 2

Expert Comment

by:mikepj
ID: 7007443
You could use Opus DirectAccess (www.opus.ch).  It's open source now and it's very fast.  BDE is easier but not as powerful or fast.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question