Solved

Findkey doesn't work with TClientDataSet - TDataSetProvider - TAdoTable

Posted on 2010-09-17
9
1,984 Views
Last Modified: 2012-05-10
Hi,

I have a access table with a filed primarykey (string file)
Last month i put a form in delphi to use this table with :
1°) Tadoconnection (i tried cursorlocation with clUseClient - and cluseserver aind i tried connectionstring based on Microsoft ole db provider for odbc driver and microsoft jet 4.0 old db provider)
2°) TAdotable (cursorlocation = clUserServer, Locktype = ltBatchOptimistic, Tabledirect = True) based on Tadoconnection
3°) TDataSetProvider based on TAdotable
4°) TClientDataSet (i tried with IndexFieldNames and without IndexFieldNames) based on TDataSetProvider
==> TClientDataSet.FindKey(['Value']) was OK

I re-do this form this week and TClientDataSet.FindKey(['Value']) not work (don't find the record).

The acces table has no change between this. I believe it's in the parameter of my components but i don't find where.
Other possibility : i d'ont remenber if last month i create the connection string in delphi conception or if i used a .udl filed : but normally there are no difference.

Thanks for your answer

0
Comment
Question by:fprovin
  • 5
  • 4
9 Comments
 
LVL 32

Expert Comment

by:ewangoya
ID: 33704143
It works fine, you have to set the IndexFieldNames for the clientdataset eg

  Clientdataset1.IndexFieldNames := 'FIRSTNAME';
  Clientdataset1.FindKey([Edit1.Text]);
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 33706064
Read this article about Locate and FindKey
http://edn.embarcadero.com/article/29176
0
 

Author Comment

by:fprovin
ID: 33707057
Hi ewangoya,

Thanks but i tried this and it's not work too (return of findkey : False).
I agree that for this table i may use locate because it's a small table but i have the same problem with a big table (more than 100 000 records and it's going up) and i am afraid about locate performance when i will arrive at 500 000 records or more...

Best regards
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 33709866
if the clientdataset is indexed, Locate will use the index. However if there are no appropriate indexes, then it resorts to scanning the dataset one record at a time, this is when you loose alot of performance
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:fprovin
ID: 33710701
I 'am ok with you but if findkey does'nt work it's probably because it doesnt use the index ? and if yes locate will do the same thing ?

And i don't understand why findkey doesn't work.

Best regards
0
 

Author Comment

by:fprovin
ID: 33710827
Hi,

In the zip there are my delphi source and the access data base
Three comments :
1°) i add a ".txt" extension on many source file to have the possibilitie to send the zip here.
2°) When you open the sources you had to activate the TClientDataSet (unit and form 7).
3°) Depends on your path you will have to change the connection string on the tadoconnection (unit and form 8)

When you clic on the "button 2" you have first a try with findkey and second with locate.
If you look step by step the findkey doesn't work.

Best regards
TestFindkey.zip
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 33713001
Here is your error, b is in lower case  
DataModule7.clientdataset1.IndexFieldNames := 'NomVariable';
  if (DataModule7.clientdataset1.FindKey(['bGestionFraisboursiers'])) then
  begin
    {coucou}
    stest := 'Ok' ;
  end ;

 bGestionFrais b oursiers   //b is in lowercase so the word is not found
check if your index is case sensitive
0
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 33713073
Here is a solution
Create a case insensitive index on TClientDataset1 then change the IndexName before searching

procedure TForm4.Button2Click(Sender: TObject);
var
stest: String ;
begin
  //I created an Index called searchkey in DataModule7
  DataModule7.ClientDataSet1.IndexName := DataModule7.ClientDataSet1.IndexDefs.Items[0].Name;
  if (DataModule7.clientdataset1.FindKey(['bGestionFraisboursiers'])) then
  begin
    {coucou}
    stest := 'Ok' ;
  end ;

  {DataModule7.clientdataset1.IndexFieldNames := 'NomVariable';
  if (Datamodule7.ClientDataSet1.Locate('NomVariable','bGestionFraisBoursiers',[])) then
  begin
    {coucou}
    stest := 'Ok' ;
  end ;}
end;
Unit7.zip.zip
0
 

Author Closing Comment

by:fprovin
ID: 33715796
Diagnostic OK
Solutions for the problem and more .
Very goog

Thanks
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now