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
WormsWormsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yurastaubCommented:
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
0
emadatCommented:
0
geobulCommented:
Hi,

Use ADO components. Place one TADOConnection on a form (or better use DataModule for all db components). Place one TADOQuery also. Set ADOQuery1.Connection property to the ADOConnection1.

1. Connecting to the db (in an event which gets fired on program startup, MainForm.OnActivate for example):

with ADOConnection1 do begin
  ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Password=MyPass;Data Source=C:\test.mdb;Persist Security Info=True';
  LoginPrompt := false; // dont prompt for login/pass
  Connected := true;
end;

You may not pass username and password directly in the connection string. Then LoginPrompt should be true and there will be a login dialog box automatically.

2. Retreiving information

with ADOQuery1 do begin
  Close;
  SQL.Clear;
  SQL.Add('SELECT * FROM Table1');
  SQL.Add('WHERE Field1=' + QuotedStr(Edit1.Text));
  Open;
  First;
  while not EOF do begin
    // do something with the current record:
    ShowMessage(FieldByName('Field2').AsString);
    Next;
  end;
  Close;
end;

Regards, Geo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

hetturkiCommented:
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


0
WormsWormsAuthor Commented:
Thanks guys. I actually figured it out from the help file.



WormsWorms
0
WormsWormsAuthor Commented:
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
0
CleanupPingCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.