我的类中有函数,它获取查询字符串并返回二维对象数组:
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
当我提供最初返回 156000 条记录的查询时。(在 toad for mysql 中),对象数组仅包含 71875 条记录。这是由于 DataReader 限制还是由于泄漏操作内存?不会抛出异常。
有任何想法吗?