Hi,
Your requirement sounds interesting, but i am not sure where are you stuck
using StringBuilder , you can easily achieve this , keep the number part separate as you want to increase it for every new selection , and maintain a history of last asign number and code in different variables.
I am not sure how you are using the Database , but i hope you can do it easily. but still for your reference please see this link
http://msdn.microsoft.com/en-us/library/2839d5h5(v=vs.110).aspx[
^]
I hope it solves your problem... please comment if it works for you :)