You
You

Reputation: 47

Stack Overflow VB.net SQL Query

I am getting through about 5000 queries before I get a stack overflow exception at the line where I call NewQuery2 again. Any ideas on what I can do to prevent this? I am trying to run about 40,000 queries.

Public Sub NewQuery2()
        Dim ID2 As String
        Try
            Dim ID As String
            ID = listBox1.Items(Next1)
            ID2 = ID
            Dim sql As String = "select INIT.MPI_MEMHEAD.MEMSTAT from INIT.MPI_MEMHEAD where INIT.MPI_MEMHEAD.MEMIDNUM = '" + ID + "'"
            Dim cmd As New OracleCommand(sql, conn)
            cmd.CommandType = CommandType.Text
            Dim dr As OracleDataReader = cmd.ExecuteReader()
            dr.Read()
            If dr.GetString(0) = "M" Then
                txtMerge.Text = txtMerge.Text + 1
            Else
                textBox1.Text = textBox1.Text + 1   
            End If
            dr.Dispose
            cmd.Dispose
        Catch ex As Exception   
            richTextBox1.Text = richTextBox1.Text + ex.Message + vbCrLf + ID2 
        End Try 
        Application.DoEvents
        If Next1 = listbox1.Items.Count - 1 Then
            conn.Dispose
        Else        
            Next1 = Next1 + 1
            NewQuery2()
        End If
    End SUb 

Upvotes: 0

Views: 57

Answers (1)

rory.ap
rory.ap

Reputation: 35260

This is happening because you're calling the method recursively from within itself and it's running out of stack space. Try creating an external method instead that loops through your listbox and calls this method (without the call to itself, of course).

Upvotes: 1

Related Questions