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 17:15:56
 
 
To
16/10/2006 04:07:42
General information
Forum:
Microsoft SQL Server
Category:
Import/Export
Miscellaneous
Thread ID:
01162137
Message ID:
01162337
Views:
20
>
>                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
>
On second thought, there is something wrong with this code. For each insert, there are now two records being inserted. This is like that since I added the SELECT SCOPE_IDENTITY() in the SQL with the ExecuteScalar().
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