REFRESHING DBGRID IN D7
-
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 either Update, Insert or Delete a record in the table. How do I get the DBGrid to automatically display the updated table? I have tried to Refresh or Update the DBGrid, also Close and Open, and Active=False and True on the ADOQuery, all to no avail. I tried to define a TDataSource which I can Create before running the query and FreeAndNil afterwards but, I get an error 'Not enough parameters' when I do MyDataSource := TDataSource.Create. I think this approach could work? Hannes
-
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 either Update, Insert or Delete a record in the table. How do I get the DBGrid to automatically display the updated table? I have tried to Refresh or Update the DBGrid, also Close and Open, and Active=False and True on the ADOQuery, all to no avail. I tried to define a TDataSource which I can Create before running the query and FreeAndNil afterwards but, I get an error 'Not enough parameters' when I do MyDataSource := TDataSource.Create. I think this approach could work? Hannes
Are you generating programatically DataSource for DBGrid? When you use Close then Open of DataSource object then it must display changes which you made from Update or Delete or Insert. Otherwise provide more detailed your case. :)
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
-
Are you generating programatically DataSource for DBGrid? When you use Close then Open of DataSource object then it must display changes which you made from Update or Delete or Insert. Otherwise provide more detailed your case. :)
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
All I have is an ADOQuery, an ADODataSource and a DBGrid. I tried to create the ADOQuery and DataSource programmatically but it did not work. I have not tried to do the same with the DBGrid. To my knowledge a DataSource does not have an Active, Close, Open or Refresh property, that's why I tried creating and freeing it but the data still did not change in the DBGrid.
Str := 'UPDATE tblTransaction SET tblTransaction.Category = "' + NewCat+ '", ' +
'tblTransaction.TaxDeductable="' + NewExp + '" ' +
'WHERE (((tblTransaction.Category) = "ZZZZ"));';
cmdCategory.CommandText := Str;
cmdCategory.Execute;
ShowData;//and then this bit in the ShowData procedure
with qryCategory do
begin
Active := False; //I also tried Close and Open
ConnectionString := cnnStr;
SQL.Text := 'SELECT Category,Expense FROM tblCategory ORDER BY Category';
Active := True;
end;//The DBGrid should now show this change
-
All I have is an ADOQuery, an ADODataSource and a DBGrid. I tried to create the ADOQuery and DataSource programmatically but it did not work. I have not tried to do the same with the DBGrid. To my knowledge a DataSource does not have an Active, Close, Open or Refresh property, that's why I tried creating and freeing it but the data still did not change in the DBGrid.
Str := 'UPDATE tblTransaction SET tblTransaction.Category = "' + NewCat+ '", ' +
'tblTransaction.TaxDeductable="' + NewExp + '" ' +
'WHERE (((tblTransaction.Category) = "ZZZZ"));';
cmdCategory.CommandText := Str;
cmdCategory.Execute;
ShowData;//and then this bit in the ShowData procedure
with qryCategory do
begin
Active := False; //I also tried Close and Open
ConnectionString := cnnStr;
SQL.Text := 'SELECT Category,Expense FROM tblCategory ORDER BY Category';
Active := True;
end;//The DBGrid should now show this change
After you execute Update command then try to use refresh on this way. Set ADODataSet1 as datasource to DBGrid,in desing mode set connection string and CommandText
ADODataSet1.Close;
ADODataSet1.CommandText:='SELECT Category,Expense FROM tblCategory ORDER BY Category';
ADODataSet1.Open;Hope it will help you.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
-
After you execute Update command then try to use refresh on this way. Set ADODataSet1 as datasource to DBGrid,in desing mode set connection string and CommandText
ADODataSet1.Close;
ADODataSet1.CommandText:='SELECT Category,Expense FROM tblCategory ORDER BY Category';
ADODataSet1.Open;Hope it will help you.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
I deleted the ADOQuery and replaced it with an ADODataSet and the code is as you suggest:
with dsCategory do //now a DataSet
begin
Close;
ConnectionString := cnnStr; //cnnStr comes from Form1.
CommandText := 'SELECT Category,Expense FROM tblCategory ORDER BY Category';
Open;
end;No change :( Even Refresh and Repaint does not work. The grid looks like its refreshing (flashes) but the modified data is not displayed.
-
I deleted the ADOQuery and replaced it with an ADODataSet and the code is as you suggest:
with dsCategory do //now a DataSet
begin
Close;
ConnectionString := cnnStr; //cnnStr comes from Form1.
CommandText := 'SELECT Category,Expense FROM tblCategory ORDER BY Category';
Open;
end;No change :( Even Refresh and Repaint does not work. The grid looks like its refreshing (flashes) but the modified data is not displayed.
-
Does DBGrid have corrected datasource object? I will do simple example for you and I will send u by email.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
-
That link opens a site were I cannot download. Could you please E-mail to hbez@mweb.co.za Much indebted to you.
-
That link opens a site were I cannot download. Could you please E-mail to hbez@mweb.co.za Much indebted to you.
You should wait maybe some near to 2 minutes until timer countdown will finish.But I sent you already exaple in your email. Regards.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
-
I deleted the ADOQuery and replaced it with an ADODataSet and the code is as you suggest:
with dsCategory do //now a DataSet
begin
Close;
ConnectionString := cnnStr; //cnnStr comes from Form1.
CommandText := 'SELECT Category,Expense FROM tblCategory ORDER BY Category';
Open;
end;No change :( Even Refresh and Repaint does not work. The grid looks like its refreshing (flashes) but the modified data is not displayed.
You should use only one connection. If you set a connection string on a ADOQuery or ADOCommand then the VCL will generate a new hidden connection in the background for the component. Each connection has it's own cache inside of the driver (jet engine) for the access database. If you modify the database through one connection the other connection will not see this change immediatly. It needs about 6 to 10s to write the changes to the *.mdb file. After that the other connection has the opportunity to read the changes. ==> allways use only one connection (TADOConnection)