Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Migrating from VB6 to VB.Net

Posted on 2008-06-20
6
Medium Priority
?
1,321 Views
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
        'PURPOSE: RETURN VALUE OF IDENTITY COLUMN OF A NEWLY INSERTED RECORD
 
        '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
            .Open()
            .BeginTrans()
            .Execute(SQl, , ADODB.CommandTypeEnum.adCmdText + ADODB.CommandTypeEnum.adExecuteNoRecords)
 
 
 
            With rs
                .ActiveConnection = cn
                .Open(, , , , ADODB.CommandTypeEnum.adCmdText)
                AutoID = rs(0).Value
                .Close()
            End With
            .CommitTrans()
            .Close()
        End With
        rs = Nothing
        cn = Nothing
        'If we get here ALL was Okay
        ExecuteID = AutoID
        Exit Function
 
 
LocalError:
        m_sLastError = Err.Number & " - " & Err.Description
 
        ExecuteID = 0
 
    End Function

Open in new window

0
Comment
Question by:keptins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 21832512
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 inherit....so 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.
0
 

Author Comment

by:keptins
ID: 21832541
thanks for your input...
I'm looking for a quick and dirty solution
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 21846226
Try this:

ADODB.ExecuteOptionEnum.adExecuteNoRecords
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Author Comment

by:keptins
ID: 21846978
thanks for the solution to this...I just wish there were some easy to read resources
0
 
LVL 41

Expert Comment

by:graye
ID: 21847994
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:

http://home.hot.rr.com/graye/Articles/BeginningADO.htm
http://home.hot.rr.com/graye/Articles/SavingDataADO.htm
0
 

Author Comment

by:keptins
ID: 21848663
thanks
I see there are several books
Do you recommend any?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

636 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