Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Delphi
  4. REFRESHING DBGRID IN D7

REFRESHING DBGRID IN D7

Scheduled Pinned Locked Moved Delphi
databasequestionhelpannouncement
11 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hbez
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • H hbez

      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

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      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.

      H 1 Reply Last reply
      0
      • B Blue_Boy

        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.

        H Offline
        H Offline
        hbez
        wrote on last edited by
        #3

        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

        B 1 Reply Last reply
        0
        • H hbez

          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

          B Offline
          B Offline
          Blue_Boy
          wrote on last edited by
          #4

          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.

          H 1 Reply Last reply
          0
          • B Blue_Boy

            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.

            H Offline
            H Offline
            hbez
            wrote on last edited by
            #5

            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.

            B S 2 Replies Last reply
            0
            • H hbez

              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.

              B Offline
              B Offline
              Blue_Boy
              wrote on last edited by
              #6

              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.

              H 1 Reply Last reply
              0
              • B Blue_Boy

                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.

                H Offline
                H Offline
                hbez
                wrote on last edited by
                #7

                That is very kind of you, thanks.

                B 1 Reply Last reply
                0
                • H hbez

                  That is very kind of you, thanks.

                  B Offline
                  B Offline
                  Blue_Boy
                  wrote on last edited by
                  #8

                  You can download sample here[^]


                  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.

                  H 1 Reply Last reply
                  0
                  • B Blue_Boy

                    You can download sample here[^]


                    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.

                    H Offline
                    H Offline
                    hbez
                    wrote on last edited by
                    #9

                    That link opens a site were I cannot download. Could you please E-mail to hbez@mweb.co.za Much indebted to you.

                    B 1 Reply Last reply
                    0
                    • H hbez

                      That link opens a site were I cannot download. Could you please E-mail to hbez@mweb.co.za Much indebted to you.

                      B Offline
                      B Offline
                      Blue_Boy
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • H hbez

                        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.

                        S Offline
                        S Offline
                        sx2008
                        wrote on last edited by
                        #11

                        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)

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups