Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help getting the @@identity value after record add
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Help getting the @@identity value after record add
Divers
Thread ID:
00683658
Message ID:
00683658
Vues:
62
The following code inserts a record into a table, I need to return the value of the @@identity assigned. I try to do this in the bottom portion of the code, but it tells me the connection state is open. Previously, I had this as a totally seperate function, but then I realized that if the select @@Identity is based on the connection so it was returning a null value. Any help greatly appreciated. I have this code in a BO module. It does insert the record, I just haven't been able to return the ID value.

Kirk
    Public Function InsertTempCaseRecord(ByVal tiBlockID As Integer, ByVal tiPerID As Integer, ByVal tiProcID As Integer) As Integer
        Dim lcConnectionString As String
        lcConnectionString = "provider=sqloledb.1;server=cqi-termserv;uid=ctore;pwd=cqi00;database=ctore"
        Dim lcSQL As String
        Dim oConn As OleDb.OleDbConnection
        Dim oCommand As New OleDb.OleDbCommand()
        oCommand.CommandText = "ctInsertTempCase"
        oCommand.CommandType = CommandType.StoredProcedure

        ' Build the Parameter list -----------------------------------------------------
        ' BlockID
        Dim oParam1 As New OleDb.OleDbParameter("@t_Command", OleDb.OleDbType.Integer)
        oParam1.Value = tiBlockID
        oCommand.Parameters.Add(oParam1)
        ' coPerID
        Dim oParam2 As New OleDb.OleDbParameter("@t_Command", OleDb.OleDbType.Integer)
        oParam2.Value = tiPerID
        oCommand.Parameters.Add(oParam2)
        ' ProcID
        Dim oParam3 As New OleDb.OleDbParameter("@t_Command", OleDb.OleDbType.Integer)
        oParam3.Value = tiProcID
        oCommand.Parameters.Add(oParam3)

        'Create Connection-----------------------------------------------------------------------
        oConn = VFPToolkit.vfpData.SqlConnect(lcConnectionString)
        oCommand.Connection = oConn
        'Run Command-----------------------------------------------------------------------------
        Try
            VFPToolkit.vfpData.SqlExecute(oConn, oCommand, "actview")
        Catch
            'Exception
        End Try

        'Get the Identity Number Assigned  ------------------------------------------------------------
        Dim idView As DataView
        lcSQL = "select @@IDENTITY as LastID"
        Dim iRecords As Integer
        iRecords = 0
        idView = VFPToolkit.vfpData.SqlExecute(oConn, lcSQL, "tcAlias")

        VFPToolkit.vfpData.Select(idView)
        iRecords = VFPToolkit.vfpData.Count(idView)

        Dim drv As DataRowView
        Dim iLastID As Integer

        If iRecords > 0 Then
            For Each drv In idView
                iLastID = drv("LastID")
            Next
        Else
            iLastID = 0
        End If
        'Break Connection-------------------------------------------------------------------------
        VFPToolkit.vfpData.SqlDisConnect(oConn)
        'Set Our return Value-------------------------------------------------------------------------
        Return (iLastID)

    End Function
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform