I want to generate 3 digit random numeric string on a click event of button 'NextAvailable' in MVC3 Razor c#.net. The numeric string should be non repeated and before generation of numeric string I need to check in SQL 2008 database, that whether the string is present or not. If present, then generate a new numeric string. I am very much new to MVC-3. Is there any help for View and Controller code? Or any logic that how should i achieve this functionality? It would be a great help.
1 Answer
3 unique digits means there can only be 999 items in your database, that may or may not be a problem. also, if there are only 999 entries available, why do they need to be random?
Regardless, identifying and selecting the next item in a sequence is a problem that can be solved in your database with a stored procedure. Your controller would execute the stored procedure via a method on one of your repository objects.
It looks like this functionality is built into Sql Server 2012, otherwise, you can build your own - here is an explanation on how to do that: Generating next sequence number in sql server