我想用mysql数据库中的数据填充一个数组
这是我的代码
Dim DataBlob As String()
Dim Count As Integer
While READER.Read
Count += 1
Dim eName As String = READER(1)
Dim eSname As String = READER(2)
Dim eID As String = READER(0)
DataBlob(Count) = eSname + eName
End While
Return DataBlob
但我没有看到任何回复。可能是什么问题
注意:有一条警告说明:DataBlob is used before a value is assigned
答案 0 :(得分:0)
如果你想使用数组,只需获得第一个计数
Dim Count as integer=reader_count(0)
Dim DataBlob(count-1) As String
'subtract 1 b/c array starts at zero
Dim i as integer=0
While READER.Read
Dim eName As String = READER(1)
Dim eSname As String = READER(2)
Dim eID As String = READER(0)
DataBlob(i) = eSname + eName
i+=1
End While
另一个选择,如果你知道你的数量是有限的(让我们说你的读者总是拉动世界各国,你可能只是高估),然后当你完成后,你重新调整数组,但你必须使用保存。除非你正在处理小数组,否则我不会这样做。
'there is no way the reader will return more than 500
Dim DataBlob(500) As String
While READER.Read
Count += 1
Dim eName As String = READER(1)
Dim eSname As String = READER(2)
Dim eID As String = READER(0)
DataBlob(Count) = eSname + eName
End While
ReDim Preserve DataBlob(Count)