BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Displaying modified data - very basic question!!!

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (InterBase Express)
View previous topic :: View next topic  
Author Message
Andrew Lockwood
Guest





PostPosted: Fri May 18, 2007 4:07 am    Post subject: Displaying modified data - very basic question!!! Reply with quote



If I am displaying a dataset (IBDataSet1) in a grid, for example, and I
update a record, is it possible to see the updated information without
closing and re-opening the dataset?

Looking on the internet, it appears that this should be possible using the
"Refresh" method, but I cannot get it to work. Do I have to have an SQL
statement in RefreshSQL to use the Refresh method? If so, what should it
be?

For example, my SelectSQL statement is SELECT * FROM People

I then post an update using an IBQuery component to change the value of one
of the fields of the current record. (Or perhaps I should be using the
ModifySQL statement of my IBDataSet?)

But even after posting the update with my IBQuery and calling
CommitRetaining followed by IBDataSet1.Refresh, the updated data is not
displayed in the grid.

Am I missing something completely obvious here (I usually am!).

Thanks for any help.


Andrew Lockwood
Back to top
Loren Szendre
Guest





PostPosted: Fri May 18, 2007 4:52 am    Post subject: Re: Displaying modified data - very basic question!!! Reply with quote



Andrew Lockwood wrote:
Quote:
But even after posting the update with my IBQuery and calling
CommitRetaining followed by IBDataSet1.Refresh, the updated data is not
displayed in the grid.

Don't use CommitRetaining. Commit the sucker.

Then you have to deal with your IBDataSet component -- is it connected
to the same IBTransaction as your IBQuery? If not, then you will have to
Commit the transaction that your IBDataSet is hooked up to, because your
IBDataSet can only "see" records that existed when its transaction began.

The most tedious way is to store a reference to the primary key value of
the current record in your IBDataSet, then commit its transaction (which
will auto close your IBDataSet), then open it back up, and do a Locate
to get back to the formerly current record. You will see all the new
changes.

Cheers,

Loren
Back to top
Andrew Lockwood
Guest





PostPosted: Fri May 18, 2007 1:13 pm    Post subject: Re: Displaying modified data - very basic question!!! Reply with quote



Thanks for your comments. But ...

i) you haven't actually answered my questions about using the refresh
method. Does it not actually work?
ii) why do you say do not use CommitRetaining?
iii) I have been closing and re-opening the datasets, and using the
primary key of the table to relocate the current record. But I haven't been
able to find a way of putting the record back on the same row it was on
before the dataset closed, so it looks pretty naff to the end user when the
record suddenly moves. And it also makes it difficult to work sequentially
through a set of data when the records keep jumping about in the grid. Do
you have any suggestions?


Andrew Lockwood

"Loren Szendre" <zorenlendry (AT) yahoo (DOT) com> wrote in message
news:464ce254$1 (AT) newsgroups (DOT) borland.com...
Quote:
Andrew Lockwood wrote:
But even after posting the update with my IBQuery and calling
CommitRetaining followed by IBDataSet1.Refresh, the updated data is not
displayed in the grid.

Don't use CommitRetaining. Commit the sucker.

Then you have to deal with your IBDataSet component -- is it connected to
the same IBTransaction as your IBQuery? If not, then you will have to
Commit the transaction that your IBDataSet is hooked up to, because your
IBDataSet can only "see" records that existed when its transaction began.

The most tedious way is to store a reference to the primary key value of
the current record in your IBDataSet, then commit its transaction (which
will auto close your IBDataSet), then open it back up, and do a Locate to
get back to the formerly current record. You will see all the new changes.

Cheers,

Loren
Back to top
Bill Todd
Guest





PostPosted: Fri May 18, 2007 8:45 pm    Post subject: Re: Displaying modified data - very basic question!!! Reply with quote

Andrew Lockwood wrote:

Quote:
For example, my SelectSQL statement is SELECT * FROM People

I then post an update using an IBQuery component to change the value
of one of the fields of the current record. (Or perhaps I should be
using the ModifySQL statement of my IBDataSet?)

The easy solution is to to use the following code instead of SQL.

with IBDataSet1 do
begin
Edit;
FieldByName('SomeField').AsString := 'abc';
Post;
end;

Quote:

But even after posting the update with my IBQuery and calling
CommitRetaining followed by IBDataSet1.Refresh, the updated data is
not displayed in the grid.

Are the IBDataSet and the IBQuery using the same transaction? If they
are not and if the IBDataSet transaction uses the default isolation
level of snapshot it will not see any changes made by other
transactions. Change the isolation level to read committed.

Be very careful when you use CommitRetaining because it does not end
the transaction. This means that you can easily have a long running
transaction which will disable garbage collection and cause record
versions to accumulate if a lot of updates and/or deletes are being
done. This will cause performance to degrade.

--
Bill Todd (TeamB)
Back to top
Woody (TMW)
Guest





PostPosted: Fri May 18, 2007 9:17 pm    Post subject: Re: Displaying modified data - very basic question!!! Reply with quote

"Andrew Lockwood" <junk (AT) acousticdesign (DOT) co.uk> wrote in message
news:464d6042 (AT) newsgroups (DOT) borland.com...
Quote:
Thanks for your comments. But ...

i) you haven't actually answered my questions about using the refresh
method. Does it not actually work?

Right click on the IBDataset component and go to the Dataset Editor. Check
your SQL statements to make sure they are all there. If not, click on the
Generate SQL button and it will automatically try to create the proper SQL
statements based on the SelectSQL property. A refresh SQL must be there to
refresh the data dynamically.

Quote:
ii) why do you say do not use CommitRetaining?

Because it leaves the transaction handle open which means garbage collection
can't happen, things tend to slow down, yadda yadda yadda...

Personal note: I use CommitRetaining but in a limited context.

Quote:
iii) I have been closing and re-opening the datasets, and using the
primary key of the table to relocate the current record. But I haven't
been able to find a way of putting the record back on the same row it was
on before the dataset closed, so it looks pretty naff to the end user when
the record suddenly moves. And it also makes it difficult to work
sequentially through a set of data when the records keep jumping about in
the grid. Do you have any suggestions?

If you get the refresh to work, you won't need any other tricks. However,
you can use the BeginUpdate/EndUpdate functionality to stop the grid from
showing an update until you're ready. You can also use the LockWindowUpdate
procedure.

HTH
Woody (TMW)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (InterBase Express) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.