[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to delete the last record of a filtered ADO dataset.

Posted on 2004-10-30
9
Medium Priority
?
271 Views
Last Modified: 2010-04-05
Hi,

I have three TADOTables (1=TCompanies, 2=TClients, 3=TCompanyClients).
The last two tables are connected to the same DatabaseTable = Clients.

PROBLEM 1:
When I am on the company level and want to display a grid with the clients belonging to that company I use a filter on the TClients table.
When I an on the client level I use the Clients table without a filter.
When I delete the last record in the filtered dataset (TClients) and try to do a refresh of the table then I get an errormessage saying that the record is out of range (row changed, index bla bla bla).

PROBLEM 2:
The table TCompanyClients is only used to quickly determine if the company has any clients. It has the TCompany datasource assigned to it as the Mastersource.
If the selected company has at least one client then a menuitem "Show Clients of this company" is shown (else it will be hidden).
This table isn't updated correctly after I post or delete records into the TClients table. So the menuoption isn't correctly updated also.

Now I have solved this by closing and opening (in stead of refreshing) the TClients and TCompanyClients tables. But this is not a good solution as you can imagine.

*************************************************************
One remark: I don't want to change datasources on DBGrids, DBedits etc. on my form
*************************************************************

Please supply me with some code that will solve these two problems correctly.

Thanks a lot.
The Wiz
0
Comment
Question by:Delphiwizard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 12450961
Would you like to use TADOQuery instead of TADOTable ?
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12451968
This works for me:

procedure TForm1.adoqClientsNewRecord(DataSet: TDataSet);
begin
  adoqClients.FieldByName('COMPANY_ID').AsInteger := adoqCompanies.FieldByName('ID').AsInteger;
end;

procedure TForm1.TClientsNewRecord(DataSet: TDataSet);
begin
  TClients.FieldByName('COMPANY_ID').AsInteger := CompanyID;
end;

procedure TForm1.TCompaniesAfterScroll(DataSet: TDataSet);
begin
  CompanyID := TCompanies.FieldByName('ID').AsInteger;
  TClients.Filtered := False;
  TClients.Filter :=''
                  + 'COMPANY_ID = '
                  + IntToStr(TCompanies.FieldByName('ID').AsInteger)
                  + '';
  TClients.Filtered := True;
  if TClients.Active then
    TClients.Requery([]);
end;

procedure TForm1.TClientsAfterDelete(DataSet: TDataSet);
begin
  TClients.Requery([]);
  TCompanyClients.Requery([]);
end;

procedure TForm1.TClientsAfterPost(DataSet: TDataSet);
begin
  TCompanyClients.Requery([]);
end;
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12451988
Please remove:

procedure TForm1.adoqClientsNewRecord(DataSet: TDataSet);
begin
  adoqClients.FieldByName('COMPANY_ID').AsInteger := adoqCompanies.FieldByName('ID').AsInteger;
end;
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Accepted Solution

by:
esoftbg earned 2000 total points
ID: 12452355
download a full example from:
page:        http://www.geocities.com/esoftbg/
  link:        Q_21188624.zip
0
 

Author Comment

by:Delphiwizard
ID: 12453625
Thanks a lot. Again..... :-)
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12453631
You are welcome Delphiwizard !
:-))
0
 

Author Comment

by:Delphiwizard
ID: 12453637
I saw that you have added a description to your solutions.
That makes things a lot more easy to find.
...Stef
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12453700
Yes, it was your advice to post description as I remember    :-))
Emil
0
 

Author Comment

by:Delphiwizard
ID: 12453706
I have my moments.....
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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