utilisation SET SCOPE_IDENTITY()
Bonjour,
Je n'ai pas encore beaucoup d'expérience en SQL Server
J'analyse la syntaxe d'un SET SCOPE_IDENTITY() pour recuperer un ID autoincrement
Dans la commande ci dessous, le POINT VIRGULE qui separe l'Insert du SET @returnid = SCOPE_IDENTITY();";
Est-il nécessaire, supperflu ou incorrect !
D'une maniere plus genérale, cette syntaxe est elle bonne ?
Merci de votre aide.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| command.CommandText = @"INSERT INTO Alarms VALUES ("
+ "@DeviceBearerId, "
+ "@time,"
+ "@position); "
+ " SET @returnid = SCOPE_IDENTITY();";
command.Parameters.Add(new SqlParameter("@DeviceBearerId", memopasAlarm.DeviceBearerId));
command.Parameters.Add(new SqlParameter("@time", memopasAlarm.Time));
command.Parameters.Add(new SqlParameter("@position", memopasAlarm.Position));
SqlParameter returnId = new SqlParameter("@returnid", SqlDbType.Int);
returnId.Direction = ParameterDirection.Output;
command.Parameters.Add(returnId);
command.ExecuteNonQuery(); |