ADO to ADO.NET - Retrieve the AutoIncrement or Identity value of a column

From: Loren Dummer (ldummer_at_isaconsultants.com)
Date: 06/08/04


Date: Tue, 8 Jun 2004 15:26:57 -0500

Hello All,

I am converting a VB6 application to .Net and having problems converting the
following code.

VB6 Code:

        Dim lDataID as Long

        sSql = "SELECT * " & _
               "FROM MSMQData"

        Set adoRs = New ADODB.Recordset
        With adoRs

            .Open sSql, adoCn, adOpenKeyset, adLockOptimistic, adCmdText

            .AddNew

            !XMLData = objDOM.xml

            .Update

            lDataID = !DataID

            .Close
        End With
        Set adoRs = Nothing

I can get this to work using a SQLCommand object and pass back the
@@Identity value in an Output parameter with the stored procedure.

I cannot figure out what I should be using to convert this correctly.

Any help is appreciated.