Last post Nov 24, 2016 06:25 AM by mazhar khan india
Nov 23, 2016 06:25 PM|acmedeepak|LINK
Right now, I increment my auto value to 1 from the query
select sum(invynum+1) as invy from invytable
I use this value in my page_load event to populate data. But as the business case, I realized that if a person starts the screen and closes in middle without uploading it, The invynum+1 will be added further without any look back. Is there ny good method
to follow so that this autoincrement can be stopped if values are not entered or saved in any way so that it can be used again or put a control over it.
Mine is an internal application and limited number of users work on it so, a control over the data entry would be welcome with a code in C#,.
Nov 23, 2016 06:46 PM|PatriceSc|LINK
Not sure to get the point especially with sum rather than max... What is your db ? To me the problem is not that this value will be consumed even if the user doesn't do the final insert but rather that multiple users could generate the same value causing
Usually you are using
https://msdn.microsoft.com/en-us/library/ff878058.aspx to generate auto-incremented values. Also this value is generated on the server side just before the insert which allows to avoid collisions (compared with computing it client side maybe several minutes
before actually using the value).
Nov 24, 2016 06:25 AM|mazhar khan india|LINK
Below one of the query will help full for you.
SET @id = (select isnull(sum(invynum), 0) + 1
use into your stored procedure
Declare @id int,@finalid int
SET @id = (select ISNULL(sum(invynum),0) from invytable)
SET @finalid =@id+1
//pass @finalid as output parameter in your stored procedure