Results 1 to 3 of 3

Thread: Database - Why doesn't my Data Control reload data when I set the RecordSource?

  1. #1

    Thread Starter
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Database - Why doesn't my Data Control reload data when I set the RecordSource?

    It is natural to assume that the data for a Data Control will re-load and populate your controls when you change the RecordSource, however this is not the case.

    In addition to setting the RecordSource you also need to tell the Data Control to reload the data, and you may need to tell your controls to update themselves to show the new data too.

    This is how you can tell the Data Control to reload data like this:
    VB Code:
    1. '(change ADODC1 to the name of your data control)
    2. ADODC1.RecordSource = "..(your recordsource text here).."
    3. ADODC1.Recordset.Requery
    4. ADODC1.Refresh

    If you are showing the data in controls (textbox/grid/etc) that do not update after using the above code, you will need to refresh them too, like this:
    VB Code:
    1. ControlName.Refresh
    Last edited by si_the_geek; Jul 21st, 2007 at 01:27 PM. Reason: corrected code formatting

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Database - Why doesn't my Data Control reload data when I set the RecordSource?

    One important thing to remember when using the ADO Data Control, if at design-time you set its CommandType to 2 (adCmdTable) you cannot change its Recordsource at run-time using "SELECT * FROM TableName", it will generate an error, a workaround for this is to set its CommandType to 1 (adCmdText) at design-time.

    And to refresh a DataGrid which is normally associated with the ADO Data Control try using its Rebind method.
    Last edited by si_the_geek; Dec 16th, 2005 at 06:01 PM.

  3. #3

    Thread Starter
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Database - Why doesn't my Data Control reload data when I set the RecordSource?

    A similar issue.. if you are using a DataGrid connected to a DataEnvironment then a Refresh or Rebind does not seem to update the grid.

    The solution in this case is to re-set the datasource, eg:
    VB Code:
    1. Set DataGrid1.DataSource = DataEnvironment1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width