• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1331
  • Last Modified:

Migrating from VB6 to VB.Net

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
keptins
Asked:
keptins
  • 3
  • 2
1 Solution
 
SStoryCommented:
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
 
keptinsAuthor Commented:
thanks for your input...
I'm looking for a quick and dirty solution
0
 
grayeCommented:
Try this:

ADODB.ExecuteOptionEnum.adExecuteNoRecords
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
keptinsAuthor Commented:
thanks for the solution to this...I just wish there were some easy to read resources
0
 
grayeCommented:
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
 
keptinsAuthor Commented:
thanks
I see there are several books
Do you recommend any?
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

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