Question

Delphi Ado data set auto fresh

Asked by: SSSIAN

Hi
I am struggling with a very silly error
I using a adodataset with with a dbgrid , for a very simple mysql table
I have a very simple commandtext which is
'select * from customer_table order by customer_name'
My problem is on insert/delete/edit the dbgrid does not auto refresh with changes unless I close  the dataset and open again
Example
I have 2 records
ABC
ZZZ
i insert at the bottom
EFG
after post, the grid shows
ABC
ZZZ
EFG
I expected to see
ABC
EFG
ZZZ
I would apperciate help on this

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-28 at 04:55:15ID24766490
Tags

Delphi / ado / mysql

Topics

Delphi Components

,

Delphi Database

,

Delphi Curiosities

Participating Experts
3
Points
350
Comments
20

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. DBGrid
    Hi all, Can you give me links to commercial dbgrids? or good freewares? Regards, Zif.
  2. DBGRid
    A DBGrid is listing the records in a table, this table contains approx. 2000 records. I want user to select the number of records displayed by the DBGRid. For Instance user may select the option 'list last 50 records' or 'list last 20 records' . How can I manage to do this wi...
  3. DBGrid
    my form has one table, one DataSource and one DBGrid. I made an alias which points to database.mdb. I choose this alias from table. datasource = table1. And DBGrid = datasource1. I have 5 records on my database. But my DBGrid shows 10 records. Which are also same as my 5 reco...
  4. Delphi 6 with DBGrid
    Hell Experts I just installed delphi 6 Enterprise edition today and I'm testing dbexpress with oracle database, I added SQLConnection and SQLTable to connec to the database, and I added Dbgrid, and when I try to connect the dbgrid with datasource property it gave me th...
  5. need example (msaccess db with delphi by ado)??
    need example (msaccess db with delphi by ado)??
  6. delphi DBGrid auto posting disable
    im using delphi 6 and mysql as database. My problem is regarding the DBGrid. It is connected to the DB, but I want to disable its auto-post feature. I want it to post (or cancel) only after clicking a button. I've added the ABORT command in the OnBeforePost event of my ADO ta...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: 8080_DiverPosted on 2009-09-28 at 05:31:47ID: 25438727

Have you thought about using a TADOQuery instead of the TADODataset?  

What you probably need to do is to set the SORT property of your dataset.

 

by: epasquierPosted on 2009-09-28 at 05:40:30ID: 25438792

Looks like a bug in ADO. This makes no sense that the line would appear but not in the right place. Someone did not a good job along the line.

You could try a direct mySQL set of components. At least they will give better perf, and I suppose the management of updates is easier when the component knows exactly how the DB works.

http://www.devart.com/mydac/

If you still have the same problem with those, then this might be a dbgrid problem. You will then have to try with a DBGrid replacement (there are a few, as stringgrid and dbgrid are the worst visual components of delphi in terms of user interface - I wouldn't be to surprise if they have issues related to DB functionalities)

 

by: 8080_DiverPosted on 2009-09-28 at 07:47:23ID: 25439811

@epasquier,

Before casting aspersions, you might want to check the Help for Delphi and the TADO components. ;-)  I believe that the TADODataset component is performing as designed and as currently set up.  It is not a bug but a failure to identify all of the necessary property settings. ;-)

@SSSIAN,

Again, look at the Sort property of the TADODataset component.  To quote a portion of the Help entry for the TADODataset component's Sort property:

Set Sort to establish or change the list of fields on which the recordset is sorted.

 

by: SSSIANPosted on 2009-09-28 at 09:10:38ID: 25440545

@epasquier
sorry to ask this question, but I cannot see anywhere the Sort property of the TADODataset component
could you direct me to this
I am using delphi 2007
Due to many reasons I cannot user TADOQuery , nor do I wish to use a third party tool


 

by: 8080_DiverPosted on 2009-09-28 at 09:27:24ID: 25440706

sssian,

I don't have D2007 available to me; however, you should be able to single left click the TADODataset component and then hit the <F1> key to bring up the Help for it.  Look in the Help for the Property link that will let you bring up the list of properties for a TADODataset component.  One of them should be Sort.  

Basically, you set the Sort property much like the ORDER BY clause of a SQL statement, e.g.:

YourTADODataset.Sort := 'CompanyName'

I believe that the default is ASCENDing (as it is with SQL ;-).

 

by: epasquierPosted on 2009-09-28 at 09:43:33ID: 25440865

Well, it will be difficult for us to reproduce your environment. You will have to try different things and tell us how it behaves.

The sort property is a good possibility and should be quick to test.

If it does not work, then you should try to identify the source of your problem by eliminating other possibilities. If you download the MyDAC trial version it would at least tell us if the problem comes from TADODataSet or the DBGrid. Then when the problem would be identified it would be time to decide if you should keep MyDAC or not, or find a workaround, or try other tests we might provide to help.

 

by: 8080_DiverPosted on 2009-09-28 at 10:06:31ID: 25441093

I am pretty sure that the problem is simply that the sort property is not set.  I would seriously doubt that there is a "bug" in the TDBGrid component or the TADODataset component.  If the rest of the world is not yelling about it, then it is probably a simple property setting that has not been set. ;-)

Of course, it may still be necessary to do a refresh on the TDBGrid or the TADODataset once the data has been entered (and the Sort property has been set).

 

by: Geert_GruwezPosted on 2009-09-28 at 12:37:55ID: 25442537

TAdoDataset does not have a true sort property

A descendant must implement it like TAdoQuery or TAdoTable

A grid can override this setting with it's own sorting mechanism
A DBGrid uses the sorting from the underlying dataset

A advanced grid like DevExpress has it's own sorting mechanism independant of the dataset sorting

 

by: 8080_DiverPosted on 2009-09-28 at 13:01:20ID: 25442728

Geert,

Unless the TADODataset has changed noticeably from D6, it should have a Sort property:

From the D6 Help:


Specifies the sort order of the recordset.
property Sort: WideString;
Description
Set Sort to establish or change the list of fields on which the recordset is sorted. Set sort to the name of a single field or to a comma-separated list of fields. Each field may optionally be followed by the keyword ASCENDING or DESCENDING to specify a sort direction for the field. If one of these keywords is not used, the default sort direction for the field is ascending. Set Sort to an empty string to reset the recordset to the sort order originally used when the recordsets data was first retrieved.
ADOQuery1.Sort := 'LastName ASC, DateDue DESC'
Read Sort to determine the field (or fields) on which the recordset is sorted.
Note: If the cursor is client-side (the dataset components CursorLocation property or that of an associated TADOConnection component is clUseClient) and no index already exists matching the requested field sort order, a temporary index is created. Resetting the sort order by setting Sort to an empty string automatically deletes the temporary index.

 

by: epasquierPosted on 2009-09-28 at 13:38:46ID: 25443158

I must say I have Delphi 5, 7, and 2007 and I understand SSIAN : the help is crap. The Sort property is not listed in TADODataSet. It can be found in TADOCustomDataSet thought.
So if they can transform a perfectly usable help system as it was when Borland was still Borland in such a mess, I wouldn't say that adding bugs in what worked previously is beyond CodeGear. But before shooting dogs and pointing fingers, let's be prudent and think about facts.

Thing is, and I'd like Diver to explain that fact if he believe there can't be bugs and everything is normal, the query is 'select * from customer_table order by customer_name' so it SHOULD be sorted whatever the sort property, except that some optimizations prevent the sort to occur dynamically. And that is a fact.

Still I believe Geert has pointed out something that might well be true. A property in an ancestor does not necessarily means it's working in all descendant.

But Diver is right about one thing : Why don't you use TADOQuery as it has a sort property listed in help, indicating that it must be implemented correctly (otherwise we will have a good reason to shoot at CodeGear) ? Can you tell us your reason, and test anyway with TADOQuery ? Maybe from there we could find something that works for you.

 

by: 8080_DiverPosted on 2009-09-28 at 14:17:46ID: 25443475

@epasquier,

the query is 'select * from customer_table order by customer_name' so it SHOULD be sorted whatever the sort property

The data is sorted . . . when it is first puled with the query.  However, the TADODataset is a separate entity from the query and behaves according to its own rules.

believe there can't be bugs and everything is normal

I didn't say that I believed that there can't be bugs; however, I have frequently seen developers start slinging mud at products and their providers (not only CodeGear but MS as well) when the problem is that the developers have sometimes come from a different background/language or they simply haven't delved into the properties or methods available and actually read the information about the purpose of the properties/methods.

As for the D5 and D7 Help being screwed up by CodeGear . . . sorry, I just don't buy the statement that they went back and modified the Help for those 2 and those were Borland products. ;-)

Check out the following link.  It provides a reference as to how to set the Sort property of a TADODataset:

http://www.marcocantu.com/code/md5/ADOSORT.htm

 

by: epasquierPosted on 2009-09-28 at 15:38:02ID: 25444236

>> The data is sorted . . . when it is first puled with the query.  
>>However, the TADODataset is a separate entity from the query and behaves according to its own rules.
Exact. I said : except that some optimizations prevent the sort to occur dynamically
If TADODataSet was perfect, it would work fine in any case. So I guess its own rules are not that perfect otherwise this thread would not exist

>>I have frequently seen developers start slinging mud at products and their providers
>> (not only CodeGear but MS as well)
True, and I'm a strong defender of MS for certain things. Most of the ones where everybody enjoys complaining in fact. But if I don't like a thing, I will tell also, even if all the world love it. Java for example.


>>As for the D5 and D7 Help being screwed up by CodeGear . . .
>>sorry, I just don't buy the statement that they went back and modified the Help for those 2 and those were Borland products. ;-)

Of course not. They screwed up D2007 help. D5 & D7 help files are still perfect. In fact, D7 is my (and a lot of other people) favorite.

>> Check out the following link.  It provides a reference as to how to set the Sort property of a TADODataset
I know of the Sort property usage. It is just ADO that I don't use. I usualy use Oracle direct access components, with which I never had such a mysterious problem as this one. So I guess some people out there knows how to tackle the "unavoidable problems" encountered by the guys who did ADO components - maybe the problem comes from ADO itself, I did say in my first message someone did not his job, I can't point fingers. You will never convince me that its behaviour is perfect.
Which is why I recommend TRYING myDAC just to eliminate possible causes.

 

by: Geert_GruwezPosted on 2009-09-29 at 00:13:03ID: 25446599

hmm,
i may have misled you here.

The TDataset does not have a Sort property
The TAdoDataset does, however ...
it is a interface property, meaning a descendant must implement it
normally this comes down to the 'ORDER BY ' in the query
the _RecordSet15 seems to be the one doing this

i do the same as epasquier (using direct access components from devart)
benchmarks showed the ADO components were way too slow
they have ms components too

>>nor do I wish to use a third party tool
not to brag, but ADO components are third party
Borland/Codegear just provides a wrapper component for them

 

by: SSSIANPosted on 2009-09-29 at 02:19:44ID: 25447101

ALL
I have increased the points to 350
I will share the points
Can I state that
Even using
I have even  tested with TAdoQuery , again the grid does not refresh , with the inital order statement

Both methods
require somehing  like
AdoQuery .sort::='customer_name ASC'
TADODateset :='customer_name ASC'

Thanks


 

by: SSSIANPosted on 2009-09-29 at 02:20:48ID: 25447103

increased point value

 

by: Geert_GruwezPosted on 2009-09-29 at 02:24:56ID: 25447122

i don't think the sort will solve your problem at all

i think the only way will be to close/open the query
but ... you have the option of resetting your bookmark to that last inserted record
maybe that would be a viable option for you ?

 

by: Geert_GruwezPosted on 2009-09-29 at 02:26:00ID: 25447126

out of curiosity, i'm having a look into a solution

 

by: SSSIANPosted on 2009-09-29 at 02:29:43ID: 25447140

Geert_Gruwez:  
I  appreciate you looking futher into this.
At the moment the sort is crudely working, but I will have use a option of
the option of resetting your bookmark to that last inserted record


 

by: Geert_GruwezPosted on 2009-09-29 at 04:24:08ID: 25447681

i used this sample to reset the pointer after post

procedure TForm1.DatasetRefresh(Dataset: TDataset);
var bm: TBookmark;
begin
  if Dataset.Active and not Dataset.IsEmpty then
  begin
    bm := DataSet.GetBookmark;
    try
      Dataset.DisableControls;
      try
        Dataset.Close;
        Dataset.Open;
        if DataSet.BookmarkValid(bm) then
          Dataset.GotoBookmark(bm);
      finally
        Dataset.EnableControls;
      end;
    finally
      Dataset.FreeBookmark(bm);
    end;
  end;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  ADOConnection1.Connected := True;
  ADOQuery1.Open;
end;
 
procedure TForm1.ADOQuery1AfterPost(DataSet: TDataSet);
begin
  DatasetRefresh(Dataset);
end;

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:

Select allOpen in new window

 

by: SSSIANPosted on 2009-09-29 at 06:55:28ID: 25449014

Geert_Gruwez:

Thank you, this is a much better solution , i have removed the sort command

TADODateset :='customer_name ASC'
and replaced with
DatasetRefresh(Dataset: TDataset);
Regards

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...