Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Error !! Can you help ?

kishore_peddikishore_peddi Posts: 176Member

Dim Cn As OleDbConnection
Dim Cmd As OleDbCommand

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:inetpubwwwrootStudent.mdb;User ID=Admin;Password=;")
Cn.Open()
CreateStudentIdRandomly()
Catch ex As Exception

End Try
End Sub

Public Sub CreateStudentIdRandomly()

Try

Dim str As String
Dim number As Integer
Dim i As Integer
Dim r As New Random

str = String.Empty
number = 0

--> str = r.Next(100000000, 999999999).ToString()

For i = 0 To 6
If str.Substring(i, 1) = str.Substring(i + 1, 1) Then
If str.Substring(i + 1, 1) = str.Substring(i + 2, 1) Then
CreateStudentIdRandomly()
End If
End If
Next

number = CType(str, Integer)

Cmd = New OleDbCommand("Insert into T values (" & number & ")", Cn)
cmd.ExecuteNonQuery()

Catch ex As StackOverflowException

Finally

CreateStudentIdRandomly()

End Try

End Sub



Hi ,

In the above code while executing at run-time it is throwing an exception (An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll" ) at -->


Can you please give me an idea why it is happening so ?

Advance ThanX for your time & patience.

Thanks,
Kishore

Comments

  • Siavash1989Siavash1989 Posts: 105Member
    you have called a loop from within itself. or you have tried to create an object from within its own class ike this

    class form1

    f = new form1

    end class
    "Within these countries, the man who was loyal, I rewarded well, who was evil, him I punished well!"

Sign In or Register to comment.