Export (0) Print
Expand All
Expand Minimize

There may be differences in data-binding behavior

Visual Studio .NET 2003

When Visual Basic 6.0 applications that use data binding are upgraded to Visual Basic .NET, there are a few behavioral differences that you need to be aware of.

Dispose behavior for BindingCollection object has changed

When using a BindingCollection object in a Visual Basic 6.0 project, it was not necessary to set the object to Nothing; it would automatically be disposed when the form was closed.

In Visual Basic .NET, the BindingCollection Class must be explicitly disposed in the Form.Closing Event event of the form.

What to do next

  • Add the following code to the Closing event of the form where the BindingCollection object was declared. This example assumes a form named MyDataForm and a BindingCollection named ADOBind.
    ' Visual Basic .NET
    Private Sub MyDataForm_Closing(ByVal sender as Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
       ADOBind.Clear()
       ADOBind.Dispose()
       ADOBind = Nothing
    End Sub
    

Data-bound properties cannot be bound to Null values

In Visual Basic 6.0, properties of a control could be bound to a database field using the BindingCollection object; if the database value was Null, the type was automatically coerced to the type of the property.

In Visual Basic .NET, only properties that are of the String data type can be bound to a database value that is Null; due to strict typing, binding any other data type will cause a InvalidCastException error.

What to do next

  • Determine the data type for each property bound to a database field, and either remove the binding for any property whose data type is not String, or modify the database so that it does not allow Null values.

See Also

Data Changes in Visual Basic .NET

Show:
© 2014 Microsoft