我正在尝试制作通用查询执行器功能。我希望能够向它发送一个查询字符串并让它返回一个包含结果的二维数组。下面是我如何使用 (9,x) 数组执行此操作的代码。如何使用 (y,x) 大小的数组来做到这一点?另外,我觉得必须有一种更有效的方法来做到这一点......
Dim right As Integer = 0
dbConn = New SqlConnection("hidden for security purposes")
MyCommand = New SqlCommand(queryString, dbConn)
dbConn.Open()
Dim resultArray(9, 0) As String
MyDataReader = MyCommand.ExecuteReader()
While (MyDataReader.Read())
For i = 0 To 9
If IsDBNull(MyDataReader(i)) Then
'resultArray(i, UBound(resultArray, 2)) = ""
Else
resultArray(i, UBound(resultArray, 2)) = MyDataReader(i)
End If
Next
ReDim Preserve resultArray(9, UBound(resultArray, 2) + 1)
End While
ReDim Preserve resultArray(9, UBound(resultArray, 2) - 1)
MyDataReader.Close()
dbConn.Close()
Return resultArray