Stack Overflow VB.net SQL查询

时间:2014-04-23 19:07:15

标签: vb.net

在我再次调用NewQuery2的行中出现堆栈溢出异常之前,我正在通过大约5000次查询。关于我能采取哪些措施防止这种情况的任何想法?我正在尝试运行大约40,000个查询。

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 

1 个答案:

答案 0 :(得分:1)

这种情况正在发生,因为您从内部递归地调用该方法,并且它已经耗尽了堆栈空间。尝试创建一个外部方法,然后循环遍历列表框并调用此方法(当然,不要调用自身)。