Previous | Index | Next 

[PRB] Changing properties of the data source associated with a DataGrid control can throw an exception

The migrated VB.NET application can throw a COMException error whose Message property reads “Rowset not available” if you change a property of an object – for example a Data control or an ADO Recordset – that is currently assigned to the DataSource property of a DataGrid control, as in this code:

        Set dataGrid1.DataSource = adodc1
        ' ...
        ' (later in the application)
        adodc1.RecordSource = "Select * From Customers"
        adodc1.Refresh     ' this statement throws in VB.NET

The simplest workaround for this issue is detaching the data source object from the DataGrid and re-attaching it after setting the object’s properties:

        Set dataGrid1.DataSource = adodc1
        ' ...
        ' (later in the application)
        Set dataGrid1.DataSource = Nothing          ' detach the data source
        adodc1.RecordSource = "Select * From Customers"
        adodc1.Refresh     ' this statement throws in VB.NET
        Set dataGrid1.DataSource = adodc1           ' re-attach the data source

 

Previous | Index | Next