我想用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
最佳答案
如果要使用数组,只需将计数设为1st
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
另一种选择是,如果您知道数量有限(假设您总是在阅读器中拉动“世界各国”,则可能会高估),然后在完成后重新排列数组,但必须使用preserve。除非您要处理小型阵列,否则我不会这样做。
'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)
关于mysql - VB.Net不使用数据库数据填充数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46808641/