Solved

Simple sample to access database for beginner

Posted on 2002-05-12
4
239 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now