Solved

DELPHI using DAO

Posted on 2006-11-21
24
1,558 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: how to implement a User Shortcut mapper? 1 110
Reconfigure Delphi Install? 2 51
How to renew a Delphi rad-studio licence? 5 65
enhance the following code 3 31
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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