Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (8)


HOW TO USE MS ACCESS IN DELPHI (using standard BDE Components)Format this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi 5.x (or higher)
Category:
Database Others
Skill Level:
Scoring:
Last Update:
05/30/2003
Search Keys:
delphi delphi3000 article borland vcl code-snippet "MS-ACCESS-WITH-DELPHI" "ODBC" "DELPHI-AND-MS-ACCESS"
Times Scored:
41
Visits:
21822
Uploader: Ameenudeen M
Company: Jamaliyath Software Solutions
Reference: N/A
 
Question/Problem/Abstract:
Methods to access data in MS Access Database from Delphi Application using standard BDE Components
Answer:



1. Create a Database in MS Access (say DelphiSample.mdb)
a. Create a Table (say Address) and put some dummy data in it.

2. Create a new ODBC DNS.
a. Open BDE Administrator (from Control Panel).
b. Right click and choose ODBC Administrator.
c. Click on the System DSN Tab.
d. Click on the Add button.
e. Select Microsoft Access Drive (*.MDB) from the list and click Finish.
f. Enter a Data Source Name (DSN) in the box provided (call it Jds_Test for example)
g. Click on the Select button and find your Access Database (DelphiSample.mdb).
h. Click OK to save the new DSN.
i. Close the ODBC Administrator

3. Create a BDE Alias
a. Right click on Database in the BDE Administrator
b. Select New from the popup menu
c. Select Microsoft Access Driver (*.MDB)
d. Click OK.
e. Give the new alias a name (such as Bde_Jds_Test)
f. Click the Apply button (blue arrow on the toolbar)
g. Click on the ODBC DNS entry on the right hand side of the BDE Administrator and
h. Find your new ODBC DSN (we called it Jds_Test before).
i. Click on the Apply button again.
j. Close the BDE Administrator

4. Accessing the data
a. Open Delphi
b. Create a new Project
c. Add a TDatabase Component.
d. Select the new alias from the AliasName property (we called it Bde_Jds_Test before)
e. Enter a new name in DatabaseName property (call it Delphi_Jds_Test for example)
f. Set LoginPrompt to false (do not need this for Access DBs).
g. Drop a TTable component on the form.
h. Set DatabaseName to TDatabase components DatabaseName (Delphi_Jds_Test)
i. Click on the TableName property and select the Table name from the list (Address)
j. Set Active to True.
k. Drop a TDataSource component on the form.
l. Set DataSet to the name of TTable (Table1)

5. Display the data
a. Place the data aware controls like TDBGrid, TDBEdit, TDBNavigator on the form
b. Set the Datasource property of these control to TDatasource name(DataSource1)
c. For TDBGrid, configure Column property
d. For TDBEdit, set the DataField property of each control to the respective db field.

6. Compile and Run.
a. You can add new data or edit existing data and update or delete data.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
How To Use Ms Access query in Delphi
    coet pane (May 7 2007 11:49AM)

I'm insert a row in 1 table that i took from 3 table
to stop it must delete then insert again or make table then drop after insert, I'm not yet find the right query for delete or make table then drop it
Respond

RE: How To Use Ms Access query in Delphi
hossein tajik (May 30 2008 10:43AM)

How To Use Ms Access query in Delphi
Respond

how to get table structure and query
    gautam more (May 21 2005 8:50AM)

hi
i am trying to build an application through which user should get the scripts in format of create table and insert into table_name values( . .)
and get the queries of the MDB as it is. i tried it using ODBC express
but it didnt prove fully satisfactory . can u please suggest method to do this , without using BDE. (can we do this using ODBC or DAO)

Thanxs and Regards
Gautam
Respond

How To Run Access Command From Delphi?
    Arash Danesh (Jul 26 2003 1:42PM)

How Can I Run Access Command Such As Repair DataBase , Campact ,... From Delphi Application ?
Respond

RE: How To Run Access Command From Delphi?
coet pane (May 7 2007 11:32AM)

procedure TfmCompact.FormClose(Sender: TObject; var Action: TCloseAction); begin
  Action := CaFree ;
end;

procedure TfmCompact.BtCompactClick(Sender: TObject);
var A : Variant;
begin
  if FileExists(CompactDB) then
  begin
    DeleteFile(CompactDB) ;
  end ;
  Try
    ShowSPLASH ;
    A := CreateOLEObject('JRO.JetEngine') ;

    // jika DB tidak di password
    {
    A.CompactDatabase('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + unGlobalUnit.DataSource,
                      'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + CompactDB  +
                      ';Jet OLEDB:Encrypt Database=True') ;
    }

    // jika DB ada password nya
    A.CompactDatabase('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + DBYangAkanDiCompact + ';Jet OLEDB:Database Password=' + PwdDBYangAkanDiCompact ,
                      'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + CompactDB  +
                      ';Jet OLEDB:Encrypt Database=True' + ';Jet OLEDB:Database Password=' + PwdDBYangAkanDiCompact) ;
    A := UnAssigned ;

    DeleteFile(DBYangAkanDiCompact) ;
    RenameFile(CompactDB, DBYangAkanDiCompact) ;
    DeleteFile(CompactDB) ;
    HideSPLASH ;
    MessageDlg('Compact sukses dilakukan',mtInformation,[mbOK],0) ;
    Close ;
  Except
    on E: Exception do
    begin
      HideSPLASH ;
      MessageDlg('Compact gagal dilakukan : ' + E.Message , mtInformation, [mbOK], 0) ;
    end ;
  End ;
end;

end.



Respond

Why don't you use ADO???
    Zijian Xu (Jul 17 2003 8:39AM)

It's more easiler, I think.
Respond

RE: Why don't you use ADO???
Peter efd (Mar 18 2004 5:13PM)

How do you install the ado component then?
Respond

Access Database with DBE
    Jon Lee (Jun 5 2003 9:25AM)

With this method you are able to access the Access database, but it seems that you won't be able to change and point to other Access Data during run time.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
S. Kucherov
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)