[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Simple sample to access database for beginner

Posted on 2002-05-12
4
Medium Priority
?
281 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 200 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

650 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