Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Identity Fields...
Message
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Titre:
Identity Fields...
Versions des environnements
Environment:
VB.NET 1.1
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01079204
Message ID:
01079204
Vues:
49
I am developing an application that utilizes MS SQL Server. All of my tables have a single IDENTITY Field, used as a Primary Key. As I was mulling over some code in my head, I thought about a possible problem that might crop up, and I thought it would be a good idea to ask if anyone can validate if what I am thinking is correct.

Being that ADO.Net is a disconnected data environment, I foresaw a problem with IDENTITY field, and returning the value of it when inserting a new record. I searched the internet and found some samples of how to get around this problem, by appending a SELECT command to the end of the INSERT statement (I got this idea directly from Microsoft.com). I testing the code and it works perfectly, after clearing out some bugs. But here is my concern...If multiple users are appending a large amount of data simultaneously into the same table, would the return of the IDENTITY information/row be always correct? Or would there be the possibility that I may accidentally grab someone else's generated IDENTITY value?

I am using the following INSERT Statement, as instructed by Microsoft.com
     objAdapter.InsertCommand.CommandText = "INSERT INTO tblUsers( Name ) VALUES ( @p1 );" & _
                                            "SELECT * FROM tblUsers WHERE ID = SCOPE_IDENTITY()"
________________________
Ben Santiago, MCP & A+
Programmer Analyst (SQL, FoxPro, VB, VB.Net, Java, HTML, ASP, JSP, VBS)
Eastern Suffolk BOCES - Student Data Services


Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rich Cook
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform