Migrating from VB6 to VB.Net

Posted on 2008-06-20
Last Modified: 2013-12-20
I'm trying to Migrate some code from a library (written by someone else) to VB.Net and I can't find a solution to this Call.
NO- I don't know ADO.Net (Yet)

Does anyone know How to rewrite the line with  (or what is causing this)
.Execute(SQl, , ADODB.CommandTypeEnum.adCmdText + ADODB.CommandTypeEnum.adExecuteNoRecords)

Public Function ExecuteID(ByVal SQl As String) As Long


        'SQL is a valid Insert statement.

        'ConnetionString property has been set to a valid Connection String

        On Error GoTo LocalError

        Dim cn As New ADODB.Connection

        Dim rs As New ADODB.Recordset

        Dim AutoID As Long

        With rs

            'Prepare the RecordSet

            .CursorLocation = ADODB.CursorLocationEnum.adUseServer

            .CursorType =ADODB.CursorTypeEnum.adOpenForwardOnly 

            .LockType = ADODB.LockTypeEnum.adLockReadOnly

            .Source = "SELECT @@IDENTITY"

        End With

        With cn

            .ConnectionString = ConnectionString

            .CursorLocation = ADODB.CursorLocationEnum.adUseServer



            .Execute(SQl, , ADODB.CommandTypeEnum.adCmdText + ADODB.CommandTypeEnum.adExecuteNoRecords)

            With rs

                .ActiveConnection = cn

                .Open(, , , , ADODB.CommandTypeEnum.adCmdText)

                AutoID = rs(0).Value


            End With



        End With

        rs = Nothing

        cn = Nothing

        'If we get here ALL was Okay

        ExecuteID = AutoID

        Exit Function


        m_sLastError = Err.Number & " - " & Err.Description

        ExecuteID = 0

    End Function

Open in new window

Question by:keptins
  • 3
  • 2
LVL 25

Expert Comment

Comment Utility
You'd be better off to rewrite it entirely using a data reader.

Here's an article I wrote on Visual Form Inheritance. It used SQL Data Readers entirely.  I think it also used SQL Server and stored procedures.  I wrote a clsParamBuilder class to make building the parameters for the command object simpler.  Much of it uses Interfaces i.e. instead of specifically for SQL Server or OLEDb it will use things like IDBCommand, from which SQLCommand and OLEDBCommand it is made generic to work with whichever you choose.

You could be able to download the source code and find more than sufficient examples to rewrite the existing code using ADO.NET with a DataReader, which from the looks of your code is all you'd need for readonly data.

Author Comment

Comment Utility
thanks for your input...
I'm looking for a quick and dirty solution
LVL 41

Accepted Solution

graye earned 125 total points
Comment Utility
Try this:

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.


Author Comment

Comment Utility
thanks for the solution to this...I just wish there were some easy to read resources
LVL 41

Expert Comment

Comment Utility
Yeah, that's the problem with any migration task.... you rarely have the time to read/absorb the material as you're using it.    Only after you're finished with the project, are you in a position to just scrap the old and start over from scratch (something that you couldn't do at the time).

I've got a few articles on ADO.Net that's desgined from an "classic ADO" perspective.   So, when you've got time (ha!), take a look at the following:

Author Comment

Comment Utility
I see there are several books
Do you recommend any?

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now