Solved

Database COnnection with Delphi

Posted on 2006-07-16
5
229 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
5 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 43 total points
Comment Utility
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 41 total points
Comment Utility
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 41 total points
Comment Utility
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

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

Suggested Solutions

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

10 Experts available now in Live!

Get 1:1 Help Now