Solved

DELPHI using DAO

Posted on 2006-11-21
24
1,560 Views
Last Modified: 2012-08-13
I have a DELPHI application coded using ADO. i have to change it so that all the database access to  be done via DAO. I need a code for the same. The application uses MSAccess database.
0
Comment
Question by:str_kani
  • 10
  • 9
  • 2
  • +2
24 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 17994903
Why?

This is rarely done.
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 17995044
BDE using DAO, but work with access 97 and below
0
 
LVL 12

Author Comment

by:str_kani
ID: 17995377
I need it because one of the users of the application is using DAO on all PC access database
components.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 45

Expert Comment

by:aikimark
ID: 17995852
just because they use DAO, doesn't mean that you have to use DAO.
0
 
LVL 12

Author Comment

by:str_kani
ID: 18001039
The user just wants me to recode it using DAO
0
 
LVL 7

Expert Comment

by:kfoster11
ID: 18002273
I would recommend explaining to the user that DAO and ADO can both run on the same machine.  If the user is less than understanding then setup a test machine or two and demonstrate that your app does or does not make the other apps stop working.  Then move on from there.

If not then you are going to have to replace all of the ADO components.  If you coded with a TDataModule then you will have to replace that with a 2nd TDataModule for DAO.  I recommend using a setting in an ini file or the registry telling you which data module to load and in the initialization of your app read the setting and dynamically create the datamodule that you require.  This way your app works with either ADO or DAO and you are not moving backwards.  If you have ADO controls all over the place then guess what!  
0
 
LVL 12

Author Comment

by:str_kani
ID: 18002367
I should have to do it using DAO since the DAO would allow us to use built in database function of delphi to
display fields and grids that auto handle sorting and filtering. and do get fields it just.

I have not used TDataModule
0
 
LVL 7

Expert Comment

by:kfoster11
ID: 18002505
TDataModule is just a container where you can put all of your data access code so that it is all in one place.  Good for client/server apps but not always practical.  Good Luck!
0
 
LVL 45

Expert Comment

by:aikimark
ID: 18002574
"The user just wants me to recode it using DAO"

Please have this uber-wise user share his business reason/justification for this.  We simple EE experts seem to think this is a silly idea.
0
 
LVL 12

Author Comment

by:str_kani
ID: 18136774
Can anyone please explain why ADO is preferred than DAO? Because using DAO is probably faster than ADO when working with MS Access database. I need to increase the speed of the application. I think converting ADO to DAO will increase the speed of the application much better. Also while using DAO, we can use TDatabase and TDataSets.

0
 
LVL 45

Expert Comment

by:aikimark
ID: 18138841
* DAO is "functionally stabilized" -- no more enhancements are planned for this abstract layer.

* While DAO was created along with the JET engine, it has features you may not need for reading/writing data. (TableDefs, Indexes, Relationships, etc.)  This may be more overhead than ADO and may run slower.

* Since MSAccess was originally designed for hard drive residency, any other configuration will be relatively slow no matter which layer you use (DAO or ADO).  If performance is a concern, you should migrate the MSAccess database to a format that has its own server engine that can run on a separate (server) PC.

* What does your uber-wise user say?  We should be addressing their misconceptions.

* Without more information about the details of your data processing, it is difficult to advise you on steps that will boost your application's performance.  Please consider the following:
1. Placement of the database (local hard drive or LAN file server -- how far away)?
2. Number of simultaneous users?
3. Profiles of the user/application access (% read only, % read with update, % appending new data, % deleting, % other SQL statements).  Also, knowing volume of data will be helpful to us.
4. Known activities (code segments) that you've identified as having a performance problem.
5. Health of the MSAccess database?  (frequency of repair & compact operations)
Does the performance degrade over time?
6. UI issues.  Does the application use bound controls?  Is screen updating suspended during batch processing?  Are you using a DataModule?
0
 
LVL 12

Author Comment

by:str_kani
ID: 18139036
I discussed about the features of both DAO and ADO to my user and he asked whether there is any way for using standard datasets and databases using ADO?if you can do this then i just want it setup so we can connect better grids and database editing items via the datasets. could you please say how to attain this?
0
 
LVL 12

Author Comment

by:str_kani
ID: 18145680
I need a code to load cxgrid with the records from the table. Where can i get the code for complete database operations using cxgrid?

I think this will lead to get over the conversion from DAO to ADO(this is requested to make the fetching of records faster). i think using cxgrid will improve the performance much better.

I am using MS Access database.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 18147374
Have you tried the TADO_____ components?
0
 
LVL 12

Author Comment

by:str_kani
ID: 18150688
I tried with TADO components but i do not know how to set the datasource in the cxgrid.

My code is here...

procedure TForm1.Button1Click(Sender: TObject);
var
  rscon:TADOdataset;
begin

app_dir:=ExtractFilePath(application.ExeName);
connect;
rscon:=TADODataset.create(nil);
rscon.Connection :=con;
rscon.CommandText :='select * from tbl_test';
rscon.open;

cxGrid1DBTableView1.DataController.RecordCount := rscon.RecordCount;

cxGrid1DBTableView1.DataController.DataSource:=rscon.DataSource;

//***The following code is also not working - just assigning a valule to the cell of the grid***

{cxGrid1DBTableView1.DataController.Values[1,0] :='some text goes here';
cxGrid1DBTableView1.DataController.Values[1,1] :='some other text goes here';
cxGrid1DBTableView1.DataController.Values[1,2] :='';
cxGrid1DBTableView1.DataController.Values[1,0] :='some other other text goes here';
cxGrid1DBTableView1.DataController.Values[1,1] :='some other other other text goes here';
cxGrid1DBTableView1.DataController.Values[1,2] :='';  }

end;

procedure TForm1.connect();
begin
  app_dir:=ExtractFilePath(application.ExeName);
  con := TADOConnection.Create(nil);
  con.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password="";Data Source='+app_dir+'test.mdb;Persist Security Info=False';
  con.Open();
 
end;

Whn i run this application, a popup appears asking the username amd password for the database. i entered nothing in that popup but clicked ok. No records are displayed in the grid.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 18153650
since this is an MSAccess database, try 'sa' for the username and an empty string, '', for the password.
0
 
LVL 12

Author Comment

by:str_kani
ID: 18156806
It didn't work. Is this the problem in displaying records in the grid from the table?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 18158561
I don't see a TDataSource object.
You might need rscon.CommandType:=cmdText;

What version of MSAccess database are you opening?
0
 
LVL 12

Author Comment

by:str_kani
ID: 18172898
I tried setting the command type. But not worked. I am using MSAccess 2000.

For your information, the grid has the number of rows equal to the number of records in the table, but the record values are not displayed.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 18173274
what about the TDataSource object?
0
 
LVL 12

Author Comment

by:str_kani
ID: 18179887
When i set the field names of the table for the field values for cxGrid1DBTableView1Column1, it got worked. Now it is displaying all the records from the table in the grid.

Thanks for all of your support
0
 
LVL 45

Expert Comment

by:aikimark
ID: 18181335
glad I could help (a little).  I'm not familiar with cxGrid, so I concentrated on the ADO bits.  Hopefully, you won't have to change your Delphi code.

btw...there is a TBetterADODataset component you might want to explore in your spare time.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 18221883
PAQd, 500 points refunded.

DarthMod
CS Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question