问题描述
大家好,我定义了一个DataTables列表
Hi guys, i defined a list of DataTables
Dim PreSubTables As New List(Of DataTable)()
然后我解析一些源文件,并根据数据进行解析,列表PreSubTables2中的任何表都可能没有填充,因此它只是一个空列表.
稍后,当我引用列表中的第一个表时,出现索引超出范围错误"
Then I parse some source files and depending on the data, possibly none of the tables in the list PreSubTables2 is populated, so it''s just an empty list.
Later on when i refer to the first table in the list , I get "index out of range error"
If (PreSubTables(0).Rows.Count > 0) Then ...
' just dealing with the first table: PreSubtables(0)
For ii = 0 To (PreSubTables(0).Rows.Count - 1)
'print the row
next
end if
在我指代``.count''的行上...
我只是想拿出一行来检查是否填充了列表中的(至少第一个)表,所以我可以将其打印出来或做其他事情.
on the line where I refer to ''.count''...
I''m just trying to come up with a line that checks whether the(at least the first)Table in the list is populated, so I can print it out or do other things. suggestions?
推荐答案
If(PreSubTables.Tables.Count > 0)
' this means there is some table
If(PreSubTables.Tables(0).Rows.Count > 0)
' This means there is some row in table 1
' Do your stuff
End If
End If
If (PreSubTables.Count > 0) Then
If (PreSubTables(0).Rows.Count > 0) Then
这篇关于“索引超出范围";错误.需要检查是否填充了DataTable以避免这种情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!