 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Boefje Guest
|
Posted: Wed Jan 18, 2006 5:28 pm Post subject: How to update/refresh/repaint TDBGrid? |
|
|
Hello,
I have got a TDBGrid component and it is filled with data retrieved
(with the help of a TADOQuery component and a TDatasource). The
SQL-statement is a SELECT with multiple JOINS. So far, so good, no
problem.
One of the fields I show in the grid is named "Status". After some user
action the value of the field "Status" must change. As far as I know, I
can not simply change the field like this:
MyDBGrid.Datasource.Dataset.Edit;
MyDBGrid.DataSource.Dataset.FieldByName('Status').AsInteger := 3;
MyDBGrid.Datasource.DataSet.Post;
This will result in a message like this
"Insufficient key column information for updating or refreshing".
When I search in the usenet groups, I read this has to do with the
primary key of the table. In this case the tables don't have primary
keys. (Whaaaaaaaaaaaat??? No, I am not kidding)
That is probably the reason why, or it is because the dataset is a
result of the SELECT over more than one table, so how should ADO know
how to update? Is that correct?
So what I do is just use another TADOQuery component with a TDataSource
and I update the field status in the correct table. Piece of cake.
But my DBGrid is not updated or repainted. What do I have to do to have
it refreshed/repainted? The only field which has been changed is the
field "status" of the current record (row). Please don't tell me I have
to execute the query again, to have the DBGrid being updated. What
should I do?
Can you push me in the right direction?
Thanks.
Daniel
|
|
| Back to top |
|
 |
Boefje Guest
|
Posted: Thu Jan 19, 2006 1:33 pm Post subject: Re: How to update/refresh/repaint TDBGrid? |
|
|
I found the answer in another post: "How to keep position row in
dbgrid?", posted by Bpk. Adi Wira Kusuma and answered by Steve
Zimmelman
The example Steve provided works perfectly for me. Steve thanks!
Here is the code slightly modified
usage:
RefreshQuery(AdoQuery1,Null,'ID');
or
RefreshQuery(AdoQuery1,AdoQuery1.FieldByName('ID').AsInteger);
procedure RefreshQuery(pADOQuery : TADOQuery; pValue :Variant;
pFieldName: string = '');
var
lValue : Variant ;
begin
lValue := Null ;
if (pFieldName <> '') and pADOQuery.Active then
begin
if pFieldName <> Null then
lValue := pValue
else
if (pADOQuery.FindField(pFieldName) <> nil) then
lValue := pADOQuery.FieldByName(pFieldName).Value ;
end;
try
pADOQuery.DisableControls ;
if pADOQuery.Active Then
pADOQuery.Requery
else
pADOQuery.Open ;
if (lValue <> Null) Then
begin
try
pADOQuery.Locate(pFieldName, lValue,[]);
except
{ Older versions of ADO raise an error if the locate fails.
Just ignore }
end;
end;
finally
pADOQuery.EnableControls ;
end;
end;
|
|
| Back to top |
|
 |
Riki Wiki Guest
|
Posted: Fri Jan 20, 2006 11:00 pm Post subject: Re: How to update/refresh/repaint TDBGrid? |
|
|
Hoi Boefje
Great that you found the solution on your own. When you post next time, you
need to be aware of the importance of posting to the Borland news server,
otherwise only very few people will ever see your post.
Take a look here:
<http://tinyurl.com/8m5nw>
which links to
<http://delphi.wikicities.com/wiki/Delphi_Newsgroups>
|
|
| Back to top |
|
 |
|
|
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
|
|