Board index » delphi » TQuery DataSet did not get updated when insert a new record into a DBGrid

TQuery DataSet did not get updated when insert a new record into a DBGrid

Dear all mighty gurus,

I am implement a simple DBGrid application with a TQuery dataset attach to
it.
I am having no problem update or delete a record.  But when I insert a new
record, the record which underneath the newly open line disappear after I do
a POST function(instead of let user move to the next record, I enforce the
post action).
New record has been inserted into database,  but the dataset has not been
updated.
Refresh only reflect the old status in the dataset.
I try using TDataSet.InsertRecord.  It actually get the job done, but also a
byproduct happen.
Delphi also using the next row of record and try to insert it into database.
I got a duplicate key error message return.

I will guest that when a new record want to insert into the dataset.
Instead of open a new row for the new record, Delphi is using the current
row as a storage place.

Since my DBGrid did not contain the update to date status, I have to
re-select from the database to refresh the screen.

I am using Delphi 4.02 C/S with Informix On-line 7.x

Thanks for all the help!!
-- Ivan Chang

 

Re:TQuery DataSet did not get updated when insert a new record into a DBGrid


You have to Close and Re-Open the Query to refresh the Dataset.

Re:TQuery DataSet did not get updated when insert a new record into a DBGrid


Mohan, Stehpane,
Thanks for the help!

I try to do a refresh after post.  An error message show up -
" Table does not support this operation because it is not uniquely indexed".
Since the table's unique index is made from "field1" and "field2", I might
as well try it on another table.
This time the table is using "field1" as unique index.
The error message is not showing up, but I still can not get my dataset
updated.
I will talk to the people who do the driver installation on my system and
see if they can come up with
something!

Any help is greatly appreciated!!
-- Ivan
    Mohan Shenoy wrote in message <36C594B0.39FC8...@nexxtgen.com>...
    I guess that this error occurs because the dataset does not get
refreshed. Maybe the driver you use does not show up the primary keys in the
table. Hence it does not get refreshed.
    Ivan Chang wrote:

        Dear all mighty gurus,
        I am implement a simple DBGrid application with a TQuery dataset
attach to
        it.
        I am having no problem update or delete a record.  But when I insert
a new
        record, the record which underneath the newly open line disappear
after I do
        a POST function(instead of let user move to the next record, I
enforce the
        post action).
        New record has been inserted into database,  but the dataset has not
been
        updated.
        Refresh only reflect the old status in the dataset.
        I try using TDataSet.InsertRecord.  It actually get the job done,
but also a
        byproduct happen.
        Delphi also using the next row of record and try to insert it into
database.
        I got a duplicate key error message return.

        I will guest that when a new record want to insert into the dataset.
        Instead of open a new row for the new record, Delphi is using the
current
        row as a storage place.

        Since my DBGrid did not contain the update to date status, I have to
        re-select from the database to refresh the screen.

        I am using Delphi 4.02 C/S with Informix On-line 7.x

        Thanks for all the help!!
        -- Ivan Chang

     --
    Mohan Shenoy
    http://www.nexxtgen.com/mohan

Other Threads