[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1709
  • Last Modified:

Help migrating vb6 code to VB.net

I'm migrating a vb6 project to vb/net and I have I'm getting an error saying
name 'adStateOpen' is not declared.      

I can find anyting to on how to re-write this.  this code is below

Public Function Clone(ByVal objRecordset As ADODB.Recordset, Optional ByVal LockType As ADODB.LockTypeEnum = ADODB.LockTypeEnum.adLockBatchOptimistic) As ADODB.Recordset
        'RETURNS A CLONE (COPY OF AN EXISTING RECORDSET)
 
        Dim objNewRS As New ADODB.Recordset
        Dim objField As Object
        Dim lngCnt As Long
 
        On Error GoTo LocalError
 
        objNewRS.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        objNewRS.LockType = LockType
 
        For Each objField In objRecordset.Fields
            objNewRS.Fields.Append(objField.Name, objField.Type, objField.DefinedSize, objField.Attributes)
        Next objField
 
        If Not objRecordset.RecordCount = 0 Then
            objNewRS.ActiveConnection = objRecordset.ActiveConnection
            objNewRS.Open()
 
            objRecordset.MoveFirst()
            While Not objRecordset.EOF
                objNewRS.AddNew()
                For lngCnt = 0 To objRecordset.Fields.Count - 1
                    objNewRS.Fields(lngCnt).Value = objRecordset.Fields(lngCnt).Value
                Next lngCnt
                objRecordset.MoveNext()
            End While
            objNewRS.MoveFirst()
        End If
 
        Clone = objNewRS
        Exit Function
 
LocalError:
        m_sLastError = Err.Number & " - " & Err.Description
 
 
        If objNewRS.State = adStateOpen Then
            objNewRS.Close()
        End If
        objNewRS = Nothing
    End Function

Open in new window

0
keptins
Asked:
keptins
1 Solution
 
TimCotteeCommented:
Hello keptins,

The best solution would be to rewrite the whole shooting match with ADO.Net (not ADODB methods).

Now I realise that at this point you probably don't want to do that so the solution is to use the relevant values (either numerical ones or from the relevant enum).

If objNewRS.State = System.Data.ConnectionState.Open Then

And so on.

Regards,

TimCottee
0
 
keptinsAuthor Commented:
I'm hoping to learn ADO.net in the very near future...do you recommend any books?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now