Results 1 to 7 of 7

Thread: DBGrid not refreshing when recordset data changes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 1999
    Location
    Portland, OR, USA
    Posts
    23
    I have a DBGrid bound to a recordset in a Data Enviroment. When I change the data in the recordset by issuing a new sql statement the data in the recordset changes but the grid still shows the old data.

    I have tried setting the grid.datasource to nothing and then setting the grid.datasource to the data enviroment recordset but then nothing shows up in the grid. I've also tried using the grid.rebind and grid.refresh and nothing seems to work.

    The only way I've got it to work is to close the form that has the grid on it and then reopen it. However, I want to keep the form open and the data in the grid would change with changes in the recordset.

    Any suggestions?

  2. #2
    Lively Member
    Join Date
    Oct 2000
    Location
    New York City
    Posts
    73
    Can you paste your code? Also, how are you
    changing the data? Are you changing the SQL that
    the DE is based on?
    Rich

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 1999
    Location
    Portland, OR, USA
    Posts
    23
    The recordset is based on a SQL Server stored procedure. I use the following lines to refresh the recordset. I've tried to set the datasource after and before these lines run. deOrder is the name for the data enviroment.

    With deOrder.Commands("GetCustomerOrderSummary")
    .Parameters("CustomerId").Value = Trim(tCustomerNo)
    End With
    With deOrder.rsGetCustomerOrderSummary
    If .State = 0 Then
    .Open
    Else
    .Requery
    End If
    End With

  4. #4
    Lively Member
    Join Date
    Oct 2000
    Location
    New York City
    Posts
    73
    I don't have SQL here at work, but I think the problem is that you are not re-executing the command object. With SQL server stored procedures, the command must be executed to refresh, not just opened (I may be wrong).
    Try adding the following line to your code...
    Code:
    With deOrder.Commands("GetCustomerOrderSummary") 
    .Parameters("CustomerId").Value = Trim(tCustomerNo) 
    End With 
    
    deOrder.GetCustomerOrderSummary 'Try adding this line
    
    With deOrder.rsGetCustomerOrderSummary 
    If .State = 0 Then 
    .Open 
    Else 
    .Requery 
    End If 
    End With
    Let me know how you make out.
    Rich

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 1999
    Location
    Portland, OR, USA
    Posts
    23
    I know the recordset is getting refreshed because I've checked the recordcount and it changes with different parameters. However, the grid doesn't update with the changes.

  6. #6
    Lively Member
    Join Date
    Oct 2000
    Location
    New York City
    Posts
    73
    Try adding this one line to the end of your routine..

    Set DataGrid1.DataSource = deOrder 'DataGrid1 is your grid


    I duplicated your problem and this worked for me.
    Rich

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 1999
    Location
    Portland, OR, USA
    Posts
    23
    Thanks, that worked!

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