Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return AutoInc field from VFP table using C#
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 4.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01486849
Message ID:
01487638
Vues:
62
>Is there a way to return the value of a autoinc field when inserting into a VFP free table using C#? I'm looking for something that would be the equivalent of using scope_identity in SQL.
>
>Thanks
I have found that (assuming you connect via oledb) "SELECT @@IDENTITY" works for me. I am connected to an access database though

Here's how I've used it :
    Public Function nLog(ByVal cDescription As String, Optional ByVal cCaller As String = "Immediate Window") As Integer
        Dim da As New dsLogTableAdapters.logTableAdapter
        ' Dim c As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()
        Dim cmdGetPK = New OleDbCommand()
        cmdGetPK.CommandText = "SELECT @@identity"
        da.Connection.Open()
        Dim n As Integer = da.Insert(My.Computer.Name, Environment.GetEnvironmentVariable("username"), LogType.LogNiceTohave, LogAction.logNa, Now, 0, "", cDescription, cCaller)
        cmdGetPK.Connection = da.Connection
        Dim n2 As Long = cmdGetPK.ExecuteScalar()
        da.Connection.Close()
        Return n2
    End Function
The key is to issue the "SELECT @@identity" under the same connection as the insert.

Hope this helps.

Marc

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform