• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

how to connect to MS-Access DB

I want to create a simple website that interfaces a small Access database with a Delphi program (CGI).  I'm using D5 Professional.

I've got the CGI stuff ok (I have D2 code that handles CGI i/o without using any CGI components).

What I need is to figure out how to send SQL queries to the Access database?!  I've created an ODBC alias for the .mdb file, but now what?!  DataSource, Database, and Table components are confusing me.  

As this is my first real database app, please give me step-by-step directions to open the database and run a query against some of the tables.

Thanks in advance :-)  I'll boost the points if it's harder than [I think] it should be.

Jon
0
jsexton
Asked:
jsexton
  • 2
1 Solution
 
intheCommented:
Hi
this is basic setup for access with odbc:

,i think you have half of it done already but i post all anyway:

Odbc:

1:   Open Control Panel, and then select ODBC DataSources (32bit) .
2:   When the Data Source Administrator appears, Click Add.
3:   find the one that says  Microsoft Access Driver (*.mdb)
     click it and click finish.
4:   A dialog will popup called ODBC Microsoft Access Setup
5:   in "data source name" edit box well call it "MyAccess"
6:   description well say is "tesing msaccess connection".
7:   click select and find your .mdb file click ok to select it.
8:   click "advanced" and make sure login name and password are blank.
9:   close advanced.
10:  close microsoft access setup dialog
11:  close the  Data Source Administrator.


in delphi:

1:  start or restart delphi if its already running.
2:  start a new project
3:  drop a ttable,tdbgrid,tdatasource,tdatabase on form.

    in object inspector:

4:  datasource1 dataset : table1
5:  dbgrid datasource   : datasource1
6:  database1 aliasname :
Alias_name_You_Made
7:  database1 databasename : MyAccessDB //type some name
8:  database1 loginprompt : false
9:  table1 databasename : MyAccessDB  //is now selectable
       {
        7:  database1 databasename : MyAccess
        8:  database1 loginprompt : false
        9:  table1 databasename : MyAccess
       }
10: table1 tablename : select a table
11: database1 connected : true
12: table1 active : true

and viola table should appear with no login prompt ,at least this method works for me everytime and i only discovered it today :-)
set loginprompt to true and you get the prompt or set to
false and get no prompt.

hope this helps someone somewhere

Regards Barry
0
 
ZifNabCommented:
Hi,

It's very easy. First a few directions :

1. A table is the actual component which provides you the data.
2. A datasource is an in between component, to link a table with a data-aware component (eg DBGrid).

this very rudimentary explenation, I think articles are the best for you to understand delphi and access

eg.

general database

http://www.kaposnet.hu/books/tysdelphi4/ch18/ch18.htm

access and delphi

http://www.delphizine.com/features/1999/07/di199907bt_f/di199907bt_f.asp

http://www.wideman-one.com/gw/tech/Delphi/d3msa/D3MSA.html

Regards, Zif.
0
 
ZifNabCommented:
you could also have a look at other DelphiZine articles :

database programming part IV

http://www.delphizine.com/features/1999/02/di199902cj_f/di199902cj_d.asp

and all its precessors/successors (see article)

Zif.
0
 
jsextonAuthor Commented:
Barry, you're the man.  Zif, you are too - just a little slower ;-)

I followed your instructions and they worked perfectly.  Thanks!

Jon
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now