Hi all
Please Help me
I have the Following table
FileCode ... Name
125 .. A
126 .. B
127 .. C
and I have textbox and I want to fill it with the last value in table and increase by one like 128 .. 129 .. etc
I got it but when I try to insert in "FileCode" Column the textbox's value "128"
it got error because other one already inserted in database before me and took the number 128
how can I avoid these errors when two inserting in the same table at the same time
解决方案You have to ways of handling this...
Easiest is to let the database worry about it by using identity column (sequence) and enter it at the insert time not letting users see the number before insert is done.
Second one is harder as you have concurrency to worry about and you have to accept that you might have "holes" in your FileCode sequence
Have one table (say COUNTER) hold current max value of the FileCode
When you get current value, increase it by one immediately. Next person that comes for the number will get that increased number and will also increase it.
The holes come from users that don't finish the insert for whatever reason - they still "used up" the number.
There is third way and that is to show the user one number, but check if it exists before the insert and then change it "on the fly" and then refresh user view, but I think this is bad user experience.
Good luck!
Try like this:
1)Click[^]
2 )Create a trigger to update the FileCode while inserting Rows in Sql server