我需要遍历DataView中的行,这样我就可以从行中获取数据或对象以添加到列表框中。这是我的DataView代码。如果用户输入的ID与" CustomerID"匹配,则RowFilter设置为仅提取行的数据。领域。如何遍历已添加的行以为行中的数据创建临时对象?
'create new table for storing incident data
Dim incidentTable As DataView = CType(incidentsDataSource.Select(
DataSourceSelectArguments.Empty), DataView)
incidentTable.RowFilter = ("CustomerID = '" & custIDTextBox.Text & "'")
Dim incidentRow As DataRowView = incidentTable(0)
'declare temporary incident and store all data in corresponding fields
Dim incident As New Incident
With incident
.IncidentID = incidentRow("IncidentID").ToString
.CustomerID = incidentRow("CustomerID").ToString
.ProductCode = incidentRow("ProductCode").ToString
.TechID = incidentRow("TechID").ToString
.DateOpened = incidentRow("DateOpened").ToString
.DateClosed = incidentRow("DateClosed").ToString
.Title = incidentRow("Title").ToString
End With
答案 0 :(得分:1)
DataView
本身就是一个列表;准确的DataRowView
个对象列表。您只需遍历DataView
本身,例如
For Each row As DataRowView In myDataView
Dim name = CStr(row("Name"))
'...
Next