Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting Pkey back from sql server
Message
De
03/12/2004 17:21:54
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
VB.NET 1.1
OS:
Windows XP SP1
Database:
MS SQL Server
Divers
Thread ID:
00966751
Message ID:
00966853
Vues:
6
>Hi,
>
>Could somebody give me some clues as to what is the best way to get a newly generated pkey value back from sql server.
>
>I'm using a dataset and using the sqlcommandbuilder to automatically generate all my insert, delete and update commands. it looks a little like this :
>
>
>Dim CommandBuilder As New SqlCommandBuilder(DataAdapter)
>DataAdapter.DeleteCommand = CommandBuilder.GetDeleteCommand()
>DataAdapter.UpdateCommand = CommandBuilder.GetUpdateCommand()
>DataAdapter.InsertCommand = CommandBuilder.GetInsertCommand()
>
>Dim ObjNewRow As DataRow
>ObjNewRow = dataset.Tables(0).NewRow
>dataset.Tables(0).Rows.Add(ObjNewRow)
>
>
>I have my tables set up with integer based primary key fields which are set up to be auto-incrementing identity fields.
>
>What's the most efficent and flexible way of getting back the pkey from sql server so that it appears in the table in my dataset.
>
>I've read the MS example of creating stored procedures within sql server which perform the insert and pass the pkey back, but this mean I'd have to create a seperate stored procedure for each table, maybe a seperate sp if the same table has a different set of fields being updated
>
>Is they a better way?
>
>Many thanks, Bernard

FWIW switch from integer autoinc keys to uniqueidentifier (NewId()) as the PK. Then you would create GUID and know the key before you submit it.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform