DELPHI using DAO

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.
LVL 12
str_kaniAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
DarthModConnect With a Mentor Commented:
PAQd, 500 points refunded.

DarthMod
CS Moderator
0
 
aikimarkCommented:
Why?

This is rarely done.
0
 
Mohammed NasmanSoftware DeveloperCommented:
BDE using DAO, but work with access 97 and below
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
str_kaniAuthor Commented:
I need it because one of the users of the application is using DAO on all PC access database
components.
0
 
aikimarkCommented:
just because they use DAO, doesn't mean that you have to use DAO.
0
 
str_kaniAuthor Commented:
The user just wants me to recode it using DAO
0
 
kfoster11CEOCommented:
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
 
str_kaniAuthor Commented:
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
 
kfoster11CEOCommented:
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
 
aikimarkCommented:
"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
 
str_kaniAuthor Commented:
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
 
aikimarkCommented:
* 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
 
str_kaniAuthor Commented:
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
 
str_kaniAuthor Commented:
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
 
aikimarkCommented:
Have you tried the TADO_____ components?
0
 
str_kaniAuthor Commented:
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
 
aikimarkCommented:
since this is an MSAccess database, try 'sa' for the username and an empty string, '', for the password.
0
 
str_kaniAuthor Commented:
It didn't work. Is this the problem in displaying records in the grid from the table?
0
 
aikimarkCommented:
I don't see a TDataSource object.
You might need rscon.CommandType:=cmdText;

What version of MSAccess database are you opening?
0
 
str_kaniAuthor Commented:
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
 
aikimarkCommented:
what about the TDataSource object?
0
 
str_kaniAuthor Commented:
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
 
aikimarkCommented:
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
All Courses

From novice to tech pro — start learning today.