Solved

Simple sample to access database for beginner

Posted on 2002-05-12
4
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

737 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