Microsoft KB Archive/229701

= PRB: Listbox DTC Does Not Show Changes When Bound Recordset Changes =

Article ID: 229701

Article Last Modified on 7/16/2001

-

APPLIES TO


 * Microsoft Visual InterDev 6.0 Standard Edition
 * Microsoft Active Server Pages 4.0

-



This article was previously published under Q229701



SYMPTOMS
A Listbox Design-Time Control (DTC) does not reflect the changes in a Recordset DTC when the Recordset DTC changes; that is, if the result set of a Recordset DTC changes, the Listbox DTC does not show this changed result set.



RESOLUTION
To overcome this problem, you need to clear the Listbox DTC of its entries so the next change in the Recordset DTC reflects on the Listbox DTC.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create a new project in Visual InterDev 6.0. Add an Active Server Page (ASP) page (Asp1.asp) to the project. Create a Data Connection (Connection1) to the NorthWind Database, Nwind.mdb. Add a Recordset DTC (Recordset1) to the page. Set the properties of the Recordset to use Connection1, and use the Employees table. Add a Listbox DTC (Listbox1) to the page.</li> Right-click Listbox1 and select Properties.</li> On the General tab, set the Recordset property to Recordset1 and the Field property to the EmployeeID field.</li> Click the Lookup tab.</li> Select the Recordset option.</li> Set the Rowsource to Recordset1.</li> Set the ListField and the Bound Column each to the EmployeeID field.</li> Click OK.</li> Add a Button DTC (Button1) to Asp1.asp</li>  When the button is clicked the recordset is changed by using the recordset.setSQLText method. Add the following code to Asp1.asp to run for the onclick event of Button1. <% Sub Button1_onclick strSQL = "SELECT * FROM employees WHERE EmployeeID > 4" If Recordset1.isOpen Then Recordset1.close Recordset1.setSQLText strSQL Recordset1.open End Sub %>                       </li> Save the Asp1.asp file.</li> Right-click Asp1.asp and select View in Browser.</li> Click Button1.</li> This re-queries Recordset1 so it returns only records where the value of the EmployeeID field is greater than 4, but Listbox1 does not reflect the changes.</li></ol>

Use the following code to work around this behavior: <% Sub Button1_onclick strSQL = "SELECT * FROM employees WHERE EmployeeID > 4" If Recordset1.isOpen Then Recordset1.close Listbox1.clear Recordset1.setSQLText strSQL Recordset1.open End Sub %> Using the Listbox1.clear method resets the contents of Listbox1 and forces it to update the contents when you open Recordset1.

<div class="references_section">