我想从 DataTable 中获取所有列值并将其存储到 ListBox 中。这是我的代码
If myTableData.Rows.Count > 0 Then
For i As Integer = 0 To myTableData.Rows.Count
Dim DataType() As String = myTableData.Rows(i).Item(1)
ListBox2.Items.AddRange(DataType)
Next
End If
但是当我编译该代码时,我收到如下错误消息:
Unable to cast object of type 'System.String' to type 'System.String[]'
那么,如何解决这个问题呢?请帮我....
你可以尝试改成这样:
If myTableData.Rows.Count > 0 Then
For i As Integer = 0 To myTableData.Rows.Count - 1
''Dim DataType() As String = myTableData.Rows(i).Item(1)
ListBox2.Items.Add(myTableData.Rows(i)(1))
Next
End If
注意:您的循环需要比行数少一,因为它是从零开始的索引。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)