-
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?
-
Can you paste your code? Also, how are you
changing the data? Are you changing the SQL that
the DE is based on?
-
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
-
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.
-
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.
-
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.
-