0

I have the function in my class, which gets querystring and returns the two dimensional object array:

 Public Function GetResultsBySql(ByVal sql As String) As Object(,)
        Dim b(,) As Object = Nothing
        Dim Command As New MySqlCommand(sql)
        Dim rowCount As Int32 = -1

        Using Conn As New MySqlConnection(Me.ConnectionString)
            Command.Connection = Conn
            Command.CommandTimeout = TimeOut
            Try
                Conn.Open()
                Dim Dr As MySqlDataReader = Command.ExecuteReader
                Do While Dr.Read
                    rowCount += 1
                    ReDim Preserve b(Dr.FieldCount - 1, rowCount)
                    For j As Int16 = 0 To Dr.FieldCount - 1
                        b(j, rowCount) = Dr(j)
                    Next
                Loop
                Return b
            Catch ex As Exception
                MsgBox(ex.Message.ToString, , "GetResultsBySql")
                Return Nothing
            End Try
        End Using ' Connection 
    End Function

When I provide query which originally returns 156000 records. (In toad for mysql), object array contains only 71875 records. It's due to DataReader limits or due to leak operating memory? No exception is thrown.

Any Ideas?

GGSoft
  • 389
  • 4
  • 12
  • Why you don't start to lean OOP and create a custom class. That's more readable, safer and more efficient. The redim in the loop is also very inefficient. Use a `List(Of Object(,))` and add them in the loop, if you need an array return `list.ToArray()`. Finally, the method is prone to sql injection issues. – Tim Schmelter Oct 19 '17 at 11:34
  • @Tim Schmelter The array is not reason. `do wlile dr.read` loop doesn't continue after 71875. It must continue till 156744. It's due to some limitation. Even using List (Of Object(.)), You must give values from datareader. – GGSoft Oct 19 '17 at 11:45

0 Answers0