Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REFRESHING A DBGRID

Status
Not open for further replies.

hbez

Instructor
Mar 25, 2003
49
ZA
On a subform in my app, I use an ADOQuery, ADODataSource and DBGrid to populate a Read-only DBGrid from an Access table. I then use an ADOCommand to execute an SQL statement to Update, Insert or Delete a record in the table. The data for this comes from an Edit (not dbEdit) box or two.
How do I get the DBGrid to automatically display the modified table? I have tried to Refresh or Update the DBGrid, also Close and Open, and Active=False and True on the ADOQuery, even refreshing the sub-form, all to no avail. I even tried Create and Free on the ADOQuery and DataSource. Putting the DBGrid into Edit and then Post status also has no effect.
Only when I close the subform and re-open it from the main form, does the data displays correctly.
Any help very much appreciated.

 
What kind of db cursor are you using when you open your grid's query?
 
Are you calling 'ApplyUpdates' after 'ExecSQL'?

Roo
Delphi Rules!
 
Sorry for the late response. I'm using ADOConnection, DataSet and ADOCommand with Execute, not an ADOQuery (must do it this way to enable sorting on multiple columns in the DBGrid). With a Close and Open on the DataSet the problem seems to be resolved.

 
Back onto my favourite nemesis -- displaying updated data in a DBGrid immediately after inserting data into an Access DB from an Edit box or other non-db aware object.
I have an Access db with one table (City) andone text field (City). The form has a DBGrid, one Edit box, ADOCommand, ADOTable and DataSource dsDB. Data is entered into edt1 and the button is clicked to insert the data into the table:

<code>
procedure TForm1.btnAddRecordClick(Sender: TObject);
var
cnnStr : string;

begin
cnnStr := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=db1.mdb;Persist Security Info=False';
cmd1.ConnectionString := cnnStr;

cmd1.CommandText := 'INSERT INTO City (City) VALUES("' + edt1.Text + '")';
cmd1.Execute;

tbl1.ConnectionString := cnnStr;
tbl1.Active := Fale;
tbl1.Active := True;
end;
</code>

If I enter a city name it does not update the DB, however, when I submit the next name the previous one displays. Can anybody tell me why this funny behaviour and, also, how can it display additions immediately. By the way, closing or opening the Dataset does not chnage this behaviour.

Hannes
 
have you tried requering the DBGrid source query?

Code:
QueryName.Refresh

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top