-------------------------------------------------------------------------------
Sample Name:  ezDatabase

Description:  This sample surveys several ADODB functions, showing how 
              VB Migration Partner deals correctly with data related applications.
              
              The converted .NET sample works exactly like the original VB6 
              application - including for some bugs in the original code -
              with the help of a few migration pragmas.


Download URL: http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=58862&lngWId=1
-------------------------------------------------------------------------------

IMPORTANT NOTE
The first step to ensure that you can migrate the VB6 project to VB.NET is 
loading the original project in the Visual Basic 6 IDE, run it to ensure that 
it works fine, that all the required type libraries are installed, and that all 
file paths are correct. 
Regardless of whether you edited the source code in any way, you should save 
the VB6 project: this save operation ensures that the .vbp file includes  
the correct path and version of referenced type libraries. 
After saving the project, it's usually a good idea to compile the VB6 project
to an executable, to detect any VB6 compilation errors that would appear under 
VB.NET as well. 
(If you don't recompile the project VB Migration Partner will display a warning 
when you later load the project.)


This sample uses an Access database file called DNSdb.mdb. You can have 
VB Migration Partner copy the file to the migrated solution folder by inserting
an AddDataFile pragma at the top of the frmClassDemo.frm:

   '## AddDataFile DNSdb.mdb


The original code contains different code lines which aren't used anywhere in the
application and could cause some error in the migrated app. You can easily remark
them as showed below for UpdateTable sub:

'## ParseMode Remarks
    Public Sub UpdateTable(ByVal TableNum As Long, ByRef NewTableName As String)
        If Connected Then

            RaiseEvent Error(errActionWhileConnected$)

        Else

            If tblString.Count = 0 Or TableNum > tblString.Count Or TableNum < 1 Or NewTableName = "" Then
     
           RaiseEvent InvalidParameter("Table Number/Name is Invalid")
    
        Else
      
          tblString.Item(TableNum) = NewTableName$ 'update table name by tablenum
    
        End If

        End If
    End Sub
'## ParseMode On


Finally, you need to insert three ParseReplace pragmas in order to avoid two errors in
getting/setting a value in recordset and to fix a programming oversight:

in ezDatabase.cls file:

1)  Public Property Get Field(ByRef NameOrIndex As Variant) As String
        If Connected Then
            If dbRs(rsIndex).State = 1 Then 'Make sure we're connected
                If dbRs(rsIndex).BOF Or dbRs(rsIndex).EOF Then 'If BOF/EOF then retrieved data is ""
                    Field$ = ""
                Else
                    If IsNull(dbRs(rsIndex)(NameOrIndex)) = True Then 'If field is null, we cannot give null
                        Field$ = ""                                 'data so we must handle this.
                    Else
                                '## ParseReplace Field$ = dbRs(rsIndex)(NameOrIndex).Value
                        Field$ = dbRs(rsIndex)(NameOrIndex)
                    End If
                End If
            Else
                RaiseEvent ConnectionError(errTableNotConnected$)
            End If
        Else
            RaiseEvent Error(errNotConnected$)
        End If
    End Property

2)  Public Sub Update(ByRef rsField As String, ByRef rsNewValue As String)
        If Connected Then
            If bWritable = False Then RaiseEvent Error("Database File is set to Read Only."): Exit Sub
            If dbRs(rsIndex).State = 1 Then
                If dbRs(rsIndex).BOF Or dbRs(rsIndex).EOF Then
                    RaiseEvent Error(errStartEndofFile$)
                Else
                    '## ParseReplace dbRs(rsIndex)(rsField).Value = rsNewValue$
                    dbRs(rsIndex)(rsField) = rsNewValue$
                    dbRs(rsIndex).Update
                    RaiseEvent Updated
                    RaiseEvent FieldsChanged("Record Updated")
                End If
            Else
                RaiseEvent Error(errTableNotConnected$)
            End If
        Else
            RaiseEvent ConnectionError(errNotConnected$)
        End If
    End Sub

in frmClassDemo.frm file:

3)  Private Sub cmdAdd_Click()
        '## ParseReplace If txtField(0).Text = "" Or txtField(1).Text = "" Then
        If txtField(0).Text Or txtField(1).Text = "" Then
            MsgBox "Fields must contain data."
            If txtField(0).Text = "" Then txtField(0).SetFocus Else txtField(1).SetFocus
        Else
            ...
        End If
    End Sub
