Following code gives values in the 8th column. Following code is okay.
Dim myDataTable As System.Data.DataTable = New System.Data.DataTable
For Each row As System.Data.DataRow In myDataTable.Rows
MessageBox.Show(row.Item(7).ToString)
Next
Following code doesn't give values in the 8th row. Following code is not okay.
Dim myDataTable As System.Data.DataTable = New System.Data.DataTable
For Each col As System.Data.DataColumn In myDataTable.Columns
MessageBox.Show(col.Item(7).ToString)
Next
Any suggestion?
The DataColumn
class doesn't have an Item
property. If you want to iterate through the items of the 8th row, you can do so using the ItemArray
property of the DataRow:
For Each item In myDataTable.Rows(7).ItemArray
MessageBox.Show(item.ToString)
Next
Dim dt As New DataTable()
Dim eightRow = dt.Rows(7)
For x = 0 To dt.Columns.Count - 1
MessageBox.Show(eightRow(x).ToString())
Next
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.