Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
From VFP auto incremental key to SQL Server
Message
From
16/10/2006 04:07:42
 
 
General information
Forum:
Microsoft SQL Server
Category:
Import/Export
Miscellaneous
Thread ID:
01162137
Message ID:
01162174
Views:
22
>While I haven't tried it, my guess is that if you executed the line of code as a pass-through command to your sql 2005 provider...
>
>
>string cMyCommand = "INSERT INTO Mytable OUTPUT Inserted.MyIdentityCol VALUES ('whatever')";
>
>
>I 'believe' it will give you back a one-row, one-column result set with the key value. If that does work, it's better than having to make another round trip back to the server to get the new ID value using scopeidentity.

This works. Here is the approach I am using:
                oCommand.CommandText = cSQL

                ' In SQL Server, we can get the primary key as is
                If nBackend = 2 Then
                    oCommand.CommandText = oCommand.CommandText + "; SELECT SCOPE_IDENTITY() ;"
                End If

                ' Only add the parameters if we have some
                If oParameters2.Count > 0 Then
                    For Each oDataParameter In oParameters2
                        oCommand.Parameters.Add(oDataParameter)
                    Next
                End If

                oDataAdapter.SelectCommand = oCommand
                oDataAdapter.SelectCommand.Connection.Open()
                oDataAdapter.SelectCommand.ExecuteNonQuery()

                ' In SQL Server, we can get the primary key as is
                If nBackend = 2 Then
                    nPrimaryKey = oCommand.ExecuteScalar()
                End If
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform