Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Database COnnection with Delphi

Posted on 2006-07-16
5
Medium Priority
?
237 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

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

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…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

604 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