Board index » delphi » Inserting with a TDBGrid Problem - Part II

Inserting with a TDBGrid Problem - Part II

Hi again,

 I posted a message about a week ago and I had several responses that
didn't help me resolve the problem (but thanks for the effort!)  So I
thought that I would post a message that explains the problem a little more

I reproduced the problem in a very simple application.  One window.  A
TDBGrid and TDBNavigator share the client area.  I have a TQuery and a
TDataSource.  The TQuery has the SQL: select country, currency from
country; and is connected to the IBLocal sample Interbase database.  I
select the first row, Click on the '+' button in the navigator, edit the
new row in the first position (typing 'zzz', 'zzz') and then if I click in
another row or on the post button, one of my original rows disappears (not
quite what I described before).  I delete the row I added and then my
original row reappears.  

If I close the query and then reopen it immediately after the post then the
row is there, similarly with closing the application and reopening it.
Could this possibly be a bug?  It seems to me this would be a common
problem.  A grid is a great tool for allowing users to add, modify and
delete rows in a simple table, in a format that they are quite familiar, if
only it displayed the rows correctly.  If you can reproduce it then I'd
like to hear about it and if you have a way to avoid the problem without
having to reselect the entire result set with every post then I would be
extremely happy to hear from you.



Re:Inserting with a TDBGrid Problem - Part II

Hi Darcy !!

I posted some messages about the same problem
to the newsgroup. Unfortionatly, I got very
little answers. I Made nearly the same test-database
that you described and got the same results.

We tracked down the problem using the VCL-Source to
the point, that the Query is not Refreshable (So your grid
could not be refreshed correctly).

This behavior comes from the fact, that a TQuery has no
property IndexFieldNames, like TTabla has.

Try the following:
Take the same SQL-Statement that you used with your TQuery
and create a View in your database with it.
Now use a TTable instead of a TQuery and connect it to the
View. Before you set the TTAble active, type the Fieldname(s) of
your PrimaryKey into the property IndexFieldNames
Now, you have the same Query-result and everything works fine.
The only problem is, that you can not use Paramters.

To sum it up:
If you try to make a Refresh by Code in your test-Project like
"MyQuery.Refresh", you will get an exception, telling you, that your
Dataset is nor correctly indexed. That is your problem.

Maybe you could forward me, what answers you got (and will get), because
I cannot belive that borland sells a ClientServer-Delphi that doesn't work
with this simple test-project.

Ciao, thomas

Other Threads