Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return AutoInc field from VFP table using C#
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 4.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01486849
Message ID:
01487638
Views:
63
>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.
Previous
Reply
Map
View

Click here to load this message in the networking platform