Board index » delphi » Query Refresh Problem

Query Refresh Problem

I find that if new records are added to a table calling the refresh
function on a query does not retrieve the new data. Instead I need to
close the query and re open it.

If I need to remain at the same record when I reopen the query then I
first need to bookmark the current query and then goto the bookmark
after re-opening the query.

If a new record is added to a dataset after the current record then
using the bookmark technique the current record can then be re-located.

If the query is indexed in such a way that a new record is inserted at a
point before the current record then using the bookmark technique will
mean that the query will be reopened at a record 1 place lower than the
current record.

Does anyone know a way of refreshing a query so that it can keep its
current record and pick up any new data in the dataset, to do the job
which the Refresh function is supposed to do.

--
Nice One! Sorted!

Sent via Deja.com http://www.deja.com/
Before you buy.

 

Re:Query Refresh Problem


You must have a unique index on the table to refresh using the refresh
command and preserve the location of the current record. Otherwise you have
to use close, open and bookmarks.

Quote
Trevor Ticktock <p...@icm-computer.co.uk> wrote in message

news:87rqv8$c20$1@nnrp1.deja.com...
Quote
> I find that if new records are added to a table calling the refresh
> function on a query does not retrieve the new data. Instead I need to
> close the query and re open it.

> If I need to remain at the same record when I reopen the query then I
> first need to bookmark the current query and then goto the bookmark
> after re-opening the query.

> If a new record is added to a dataset after the current record then
> using the bookmark technique the current record can then be re-located.

> If the query is indexed in such a way that a new record is inserted at a
> point before the current record then using the bookmark technique will
> mean that the query will be reopened at a record 1 place lower than the
> current record.

> Does anyone know a way of refreshing a query so that it can keep its
> current record and pick up any new data in the dataset, to do the job
> which the Refresh function is supposed to do.

> --
> Nice One! Sorted!

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Re:Query Refresh Problem


On Wed, 09 Feb 2000 13:44:08 GMT, Trevor Ticktock <p...@icm-computer.co.uk>
wrote:

Quote
>I find that if new records are added to a table calling the refresh
>function on a query does not retrieve the new data. Instead I need to
>close the query and re open it.

[...]

This is the proper way to refresh a TQuery.

Quote
>Does anyone know a way of refreshing a query so that it can keep its
>current record and pick up any new data in the dataset, to do the job
>which the Refresh function is supposed to do.

You might try using the Locate method, searching for the original record
using column values that uniquely identify the record.

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski              "Health nuts are going to feel stupid someday,
Felton, CA                  lying in hospitals dying of nothing."
                                                              -- Redd Foxx

Re:Query Refresh Problem


I wrote a method called

Requery(DataSet: TDataSet);
var
   B: TBookMark;
begin
   DisableControls;
   B:=GetBookMark;
   Close;
   Open;
   if BookMarkValid(B) then
       GotoBookmark(B);
   EnableControls;
end;

Good Luck, Jaap

Quote
"Trevor Ticktock" <p...@icm-computer.co.uk> wrote in message

news:87rqv8$c20$1@nnrp1.deja.com...
Quote
> I find that if new records are added to a table calling the refresh
> function on a query does not retrieve the new data. Instead I need to
> close the query and re open it.

> If I need to remain at the same record when I reopen the query then I
> first need to bookmark the current query and then goto the bookmark
> after re-opening the query.

> If a new record is added to a dataset after the current record then
> using the bookmark technique the current record can then be re-located.

> If the query is indexed in such a way that a new record is inserted at a
> point before the current record then using the bookmark technique will
> mean that the query will be reopened at a record 1 place lower than the
> current record.

> Does anyone know a way of refreshing a query so that it can keep its
> current record and pick up any new data in the dataset, to do the job
> which the Refresh function is supposed to do.

> --
> Nice One! Sorted!

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Re:Query Refresh Problem


Quote
> I wrote a method called

> Requery(DataSet: TDataSet);
> var
>    B: TBookMark;
> begin
>    DisableControls;
>    B:=GetBookMark;
>    Close;
>    Open;
>    if BookMarkValid(B) then
>        GotoBookmark(B);
>    EnableControls;
> end;

I found your comment really interesting. But trying your feature a got a
fatal error exception at the line if bookmark like error inside of
idapi32.dll.
I am using Delphi 5 and the BDE 5.01 and Oracle as backend.
Any idea what is wrong?

--
Regards
Nicolas Bronke

Re:Query Refresh Problem


I wrote a similar function myself which works fine as long as records
are added to the end of a dataset. If the query is indexed (ordered by)
in such a way that records are added to the dataset at a point lower
than the current record, when you re-open the query and apply the
bookmark the cursor is moved to a point one record lower than the actual
record.

In article <950449270.11395.4.pluto.d4ee3...@news.demon.nl>,
  "J" <nos...@umbra.demon.nl> wrote:

Quote
> I wrote a method called

> Requery(DataSet: TDataSet);
> var
>    B: TBookMark;
> begin
>    DisableControls;
>    B:=GetBookMark;
>    Close;
>    Open;
>    if BookMarkValid(B) then
>        GotoBookmark(B);
>    EnableControls;
> end;

> Good Luck, Jaap
> "Trevor Ticktock" <p...@icm-computer.co.uk> wrote in message
> news:87rqv8$c20$1@nnrp1.deja.com...
> > I find that if new records are added to a table calling the refresh
> > function on a query does not retrieve the new data. Instead I need
to
> > close the query and re open it.

> > If I need to remain at the same record when I reopen the query then
I
> > first need to bookmark the current query and then goto the bookmark
> > after re-opening the query.

> > If a new record is added to a dataset after the current record then
> > using the bookmark technique the current record can then be
re-located.

> > If the query is indexed in such a way that a new record is inserted
at a
> > point before the current record then using the bookmark technique
will
> > mean that the query will be reopened at a record 1 place lower than
the
> > current record.

> > Does anyone know a way of refreshing a query so that it can keep its
> > current record and pick up any new data in the dataset, to do the
job
> > which the Refresh function is supposed to do.

> > --
> > Nice One! Sorted!

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

--
Nice One! Sorted!

Sent via Deja.com http://www.deja.com/
Before you buy.

Other Threads