VB to .NET

ADODB to Data.Common with Helpers

The VBUC incorporates the usage of the System.Data.Common library members in the translation process to ensure the generated code is taking advantage of the .NET framework 2.0 features. This option is recommended for the following scenarios:

  • ADO connecting to SQLserver: this scenario can be upgraded using the next option as well, although this option achieves higher automation ratios.
  • ADO connecting to any other provider: when ADO is used to connect to any other data provider besides SQLserver (Jet, ODBC,…) this option MUST be used.

Support for ADODC data control is added into this feature.

The member transformation for this data access technology is described as follows:

Class Maps To
ADODB.RecordSet Artinsoft.VB6.DB.ADO.ADORecordSetHelper
ADODB.Command

System.Data.Common.DbCommand

Example:

System.Data.Common.DbCommand cmd = factory. CreateCommand();

ADODB.CommandTypeEnum System.Data.CommandType
ADODB.Connection

System.Data.Common.DbConnection

Example: GetFactory() will require database- provider-name paramater in order to use the non default provider.

System.Data.Common.DbConnection conn = FactoryManager.GetFactory().CreateConnection();

ADODB.DataTypeEnum System.Data.DbType
ADODB.Field System.Data.DataColumn
ADODB.Fields System.Data.DataColumnCollection
ADODB.IsolationLevelEnum System.Data.IsolationLevel
ADODB.ObjectStateEnum System.Data.ConnectionState
ADODB.Parameter

System.Data.Common.DbParameter

Example:

System.Data.Common.DbParameter p = factory. CreateParameter();

ADODB.ParameterDirectionEnum System.Data.ParameterDirection
ADODB.Parameters System.Data.Common.DbParameterCollection
ADODB.Stream

System.IO.StreamWriter

Example:

new System.IO.StreamWriter()

Note: The file name to open or create can be otained from the values used in LoadFromFile and SaveToFile methods. FileMode and FileAccess values could require some manual changes according to the values used in LoadFromFile and SavetoFile methods.

ADODB.LockTypeEnum Artinsoft.VB6.DB.ADO.LockTypeEnum
ADODB.CursorLocationEnum Artinsoft.VB6.DB.ADO.CursorLocationEnum
ADODB.AffectEnum Artinsoft.VB6.DB.ADO.AffectEnum
ADODB.EventStatusEnum Artinsoft.VB6.DB.ADO.Events.EventStatusEnum
ADODB.EventReasonEnum Artinsoft.VB6.DB.ADO.Events.EventReasonEnum
ADODB.PositionEnum Artinsoft.VB6.DB.ADO.PositionEnum

This feature also supports the upgrade of the ADODC data control into a helper class. The supported classes are the following:

Class Maps To
MSAdodcLib.Adodc Artinsoft.VB6.DB.ADO.ADODataControlHelper
MSAdodcLib.EOFActionEnum Artinsoft.VB6.DB.Controls.EOFActionEnum
MSAdodcLib.BOFActionEnum Artinsoft.VB6.DB.Controls.BOFActionEnum

A brief source sample of this feature:

Original VB6 Code:

Public recRecordset As ADODB.Recordset
Public ADODBConnection As New ADODB.Connection

Private Sub Form_Load()

    Set ADODBConnection = New ADODB.Connection
    ADODBConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\TestDB.mdb;Mode=Read|Write;Persist Security Info=False"

    ADODBConnection.Open
    Set recRecordset = New ADODB.Recordset
    recRecordset.CursorLocation = adUseClient

    recRecordset.Open "select * from Countries", ADODBConnection, adOpenKeyset, adLockOptimistic, adCmdText

    recRecordset.Sort = "Name"
    recRecordset.MoveFirst

End Sub

Resulting VB.NET Code:

Public recRecordset As ADORecordSetHelper
Private _ADODBConnection As DbConnection = Nothing
Private Sub Form1_Load(ByVal eventSender As Object, ByVal eventArgs As EventArgs) Handles MyBase.Load

        ADODBConnection = Artinsoft.VB6.DB.AdoFactoryManager.GetFactory().CreateConnection()

        ADODBConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Application.Info.DirectoryPath & "\TestDB.mdb;Mode=Read|Write;Persist Security Info=False"

'UPGRADE_TODO: (7010) The connection string must be verified to fullfill the .NET data provider conecction string requirements. More Information: http://www.vbtonet.com/ewis/ewi7010.aspx

    ADODBConnection.Open()
        
    recRecordset = New ADORecordSetHelper("")
    recRecordset.CursorLocation = CursorLocationEnum.adUseClient

    recRecordset.Open("select * from Countries", ADODBConnection, LockTypeEnum.adLockOptimistic)

    recRecordset.Sort = "Name"
    recRecordset.MoveFirst()

End Sub

Resulting C#.NET Code:

public ADORecordSetHelper recRecordset = null;
private DbConnection _ADODBConnection = null;

private void  Form1_Load( Object eventSender,  EventArgs eventArgs)
{
    
ADODBConnection = Artinsoft.VB6.DB.AdoFactoryManager.GetFactory().CreateConnection();

    ADODBConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(Application.ExecutablePath) + "\\TestDB.mdb;Mode=Read|Write;Persist Security Info=False";

//UPGRADE_TODO: (7010) The connection string must be verified to fullfill the .NET data provider conecction string requirements. More Information: http://www.vbtonet.com/ewis/ewi7010.aspx

ADODBConnection.Open();
                
    recRecordset = new ADORecordSetHelper("");
    recRecordset.CursorLocation = CursorLocationEnum.adUseClient;

recRecordset.Open("select * from Countries", ADODBConnection,LockTypeEnum.adLockOptimistic);

    recRecordset.Sort = "Name";
    recRecordset.MoveFirst();
}

Note: The connection string might need some manual adjustments as explained in the EWI contained present in the source code.

Talk To An Engineer