前端之家收集整理的这篇文章主要介绍了
[VB.NET]数组为什么出错啊?急!!1在线等~~~,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
数组为什么出错啊?急!!1在线等~~~ 我定义了一个数组getarray(),用来接受有select语句
查询出的结果,但是运行是总、是报错说 "其他信息: 索引超出了数组界限 ",但是我并没有规定数组的大小啊? Dim getarray() As String = New String() {} Dim j,k As Integer k = 0 ...... ''select语句 For j = 0 To Ds1.disease.Count.ToString - 1 getarray(k) = Ds1.disease.Item(j).dis_name.ToString() k = k + 1 Next j disease为表名,dis_name为表的一个字段 __________________________________________________________________________ Dim getarray() As String = New String() {} Dim j,k As Integer k = 0 ''select语句 ReDim Preserve getarray(Ds1.disease.Count.ToString - 1) For j = 0 To Ds1.disease.Count.ToString - 1 getarray(j) = Ds1.disease.Item(j).dis_name.ToString() k = k + 1 '' 这个k没有必要用吧 Next j __________________________________________________________________________ ReDim一下数组,要不然它的UpperBound是-1 __________________________________________________________________________ 也可以使用动态数组啊 Dim getarray as New ArrayList Dim j,k As Integer For j = 0 To Ds1.disease.Count- 1 getarray.add( Ds1.disease.Item(j).dis_name.ToString()) Next j __________________________________________________________________________
原文链接:https://www.f2er.com/vb/263921.html