?
Solved

Database COnnection with Delphi

Posted on 2006-07-16
5
Medium Priority
?
236 Views
Last Modified: 2010-04-05
Dear Expert
I'm a beginner of Delphi programming and want to know the Database Connection of Delphi with any kind of database like Access,Oracle,mysql etc.Pls help me providing code to connect Delphi with 1) Access 2)Oracle and 3) Mysql.

Thanks in advance
0
Comment
Question by:binita11
[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
5 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 172 total points
ID: 17116885
This depends on your version of delphi.
but take a look in your program files\delphix\demos\ directory
there are some database demos there
0
 
LVL 9

Assisted Solution

by:sun4sunday
sun4sunday earned 164 total points
ID: 17117090
Here you can begin with  Fundamentals of Database Development

http://delphi.about.com/od/beginners/l/aa020601a.htm

sun4sunday
0
 
LVL 1

Assisted Solution

by:Tueblo
Tueblo earned 164 total points
ID: 17117093
The easiest waywould be to create a datasource in windows for your database. (Control panel, Administrative tools)

uses SysUtils, ActiveX, adoDB, DB, ...;

type

  TForm1 = class(TForm)
  :
  private
    FConnection : TADOConnection;
  :
  end;

functionTForm1.DatabaseConnect: Boolean;
begin
  result := TRUE;
  OleInitialize(nil);
  FConnection := TADOConnection.Create(NIL);
  FConnection.LoginPrompt := TRUE;
  FConnection.ConnectionString := PromptDataSource(0, '');
  try
    FConnection.Open;
  except
    result := FALSE;
  end;
end;

procedure TForm1.DatabaseDisconenct;
begin
  FConnection.Close;
  FreeAndNil(FConnection);
  OleUninitialize;
end;

If you do not want to have the promt dialog every time, you can also give the connection string explicitly. Example for a mySQL Database (the mentioned driver must be installed, check in the datasource dialog):

function TForm1.DatabaseConnect(databaseServer, databaseName, username, password: String): Boolean;
var connectionString : String;
begin
  result := TRUE;
  OleInitialize(nil);
  FConnection := TADOConnection.Create(NIL);
  FConnection.LoginPrompt := FALSE;
  connectionString := 'DRIVER={MySQL ODBC 3.51 Driver}; ' +
                       'SERVER=' + databaseServer + '; '   +
                       'DATABASE=' + databaseName + '; '   +
                       'UID=' + username + '; '            +
                       'PWD=' + password + '; '            +
                       'OPTION=3';
  FConnection.ConnectionString := connectionString;
  try
    FConnection.Open;
  except
    result := FALSE;
  end;
end;
0

Featured Post

Industry Leaders: 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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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