Link to home
Start Free TrialLog in
Avatar of WormsWorms
WormsWorms

asked on

MS Access and Delphi

I have an MS Access DB that I have a front end built for. I am now trying to connect the forms to the DB.

How do I call a query from within delphi and get a result set?
Can someone point me to a tutorial about how to do this? Or a specific example of what stuff I need to put on the form?


I am using Delphi 7 and Access 97.

WormsWorms
Avatar of yurastaub
yurastaub

Hi,
Lets imagine that you need to browse Access data in grid.
So, on form put TDBGrid component, TDataSource, TTable, TDatabase.
Lets set properties:
Database1.DatabaseName:='tryDB';
Database1.DriverName:=MSACCESS;
Database1.LoginPromt:=false;
Database1.Params.Clear;
Database1.Params.Add('DATABASE NAME=E:\Projects\GardenGuard\Project\pattern.mdb
');
Database1.Connected:=true;
TDBGrid.DataSource:=DataSource1;
DataSource1.DataSet:=Table1;
Table1.DatabaseName:='tryDB';

Now you can try select for Table1 TableName from List Delphi should offer. After that can set property:
Table1.Active:=true;

Now you must see in Grid1 table data.

Yura
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi
from ADO components Place one TADOConnection ,one TADOQuery and one DataSource on a form (its better to put the db component in dateModel)

1- connecting database ADOConnection1.connectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Password=MyPass;Data Source=C:\employee.mdb;Persist Security Info=True';
 ADOConnection1.LoginPrompt := false;
 ADOConnection1.Connected := true;

set ADOQuery1.connection property to ADOConnection1
connect the DataSource with ADOQuery1

2_ Put dbgrid on the form
connect DBgrid with the ADOQuery1 (dataset property of dbgrid)
3_ place bitbtn on the form
4_ Double click on DBgrid and add all FIELDS
5_ in bitbtn1.click procedure place the following code


with ADOQuery1 do begin
 
 Close;
 SQL.Clear;
 SQL.Add('SELECT * FROM EMP');
 SQL.Add('WHERE sal >= 250');
 Open;

Run the project and click on the bitbtn you will see the result

BRGS


Avatar of WormsWorms

ASKER

Thanks guys. I actually figured it out from the help file.



WormsWorms
And besides, who should I give the points to. 3 people have answers. I actually figured it out from the help file.

BUT, geobul is whining, so I am gonna give him the pionts, and I guess you other guys get screwed.

Sorry

WormsWorms
WormsWorms:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.