I have a function in asp.net vb class file which generates a unique alphanumeric string.
After generating the string, I want to check if the string already exists in sql table, if so, I want to repeat the process.
Please find the code I am using
Public Function GenerateUniqueID() As String
Dim numbers As String = "1234567890"
Dim characters As String = numbers
Dim length As Integer = 5
Dim UID As String = String.Empty
For i As Integer = 0 To length - 1
Dim character As String = String.Empty
Do
Dim index As Integer = New Random().Next(0, characters.Length)
character = characters.ToCharArray()(index).ToString()
Loop While otp.IndexOf(character) <> -1
UID += character
Next
'-----------
check if UID already exist in db
if yes
repeat same function to generate new ID
if no
return unique id
'-----------
Return UID
End Function
I want to know how can I call same function if generated ID already exist in database.