I have created a function :
Function randomid() As String
Try
Dim i As Integer
Dim temp As String = ""
Dim rnd As New Random
i = rnd.Next(100, 99999)
temp = "ABC" & i
Dim count As Integer = Dal.ExecuteScalar("select count(*) from property where property_id='" & temp & "'")
If count > 0 Then
randomid()
Else
Return temp
End If
Catch ex As Exception
End Try
End Function
And i am calling above function from within below sub :
Sub AcresImport()
For Each ..loop
Dim propId As String = randomid()
Next
End Sub
It is working fine sometimes only. I mean it is creating propId randomly for some iterations. For Ex - If there are 3 interations in the above loop, it will randomly create propId for Ist two iterations or only Ist iteration ..means radomly.
But when i debug through it, it will create all 3 propIds for 3 iterations correctly.
So i can't understand when it is working fine when i debug..then why it is not working correctly when i simply run it.
Please help.