|
| HOW TO USE MS ACCESS IN DELPHI (using standard BDE Components) | 
|
|---|
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: 27 | Visits: 15396 | 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.
|
|