VB Migration Partner

KNOWLEDGE BASE - Database and data-binding


Previous | Index | Next 

[PRB] Data classes might need manual adjustments

VB6 allows you to defined data source classes, i.e. classes or controls whose DataSourceBehavior property is set to 1-vbDataSource; such data source classes are typically used to bind controls to a data source. For example, you can use this feature to create a user control that behaves like the standard ADO Data control, possibly with a custom user interface and extended behavior.

VB Migration Partner fully supports VB6 data source classes and in most cases you don’t have to edit the original code in any way. There is a twist, though: if the class or ActiveX control supports rebinding to a different data source you need to include one or more statements in the converted VB.NET application.

For example, let’s say that the client application can assign a new value to the control’s DataSource property and then refresh the contents of all bound controls:

    ' in the client application
   MyDataControl1.DataSource = "Select * From Products Where ProductName Like 'A%'
   MyDataControl1.Refresh()

The Refresh method causes the binding infrastructure to fire the GetDataMember event, an event that all VB6 data source classes and controls must handle. When the event fires, the VB6 code is expected to recreate the data source – typically, an ADO Recordset – and pass it back to the COM binding infrastructure by means of the Data argument:

    Private Sub UserControl_GetDataMember(DataMember As String, Data As Object)
      Dim rs As New Recordset
      ' query public properties and then recreate and open the recordset
      ' ...
      ' pass the recordset back to the COM binding infrastructure
      Set Data = rs
   End Sub

As explained previously, if the data source class ever requeries the data source, you must insert a call to the VB6DataSourceWrapper.Create static method, immediately after the point where the Recordset is defined for the converted VB.NET code to work correctly:

    Private Sub UserControl_GetDataMember(DataMember As String, Data As Object)
      Dim rs As New Recordset
      ' query public properties and then recreate and open the recordset
      ' ...
      '## NOTE under .NET we must force re-binding
      '## InsertStatement VB6DataSourceWrapper.Create(rs, Me)
      ' pass the recordset back to the COM binding infrastructure
      Set Data = rs
   End Sub
Previous | Index | Next 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.




Code Architects and its partners offers remote and onsite migration services.

More details




Subscribe to our free newsletter for useful VB6 migration tips and techniques.

newsletter



To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice



A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial




The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote




Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers