【发布时间】:2017-02-17 01:49:22
【问题描述】:
我需要遍历 DataView 中的行,以便从行中获取数据或对象以添加到列表框。这是我的 DataView 代码。如果用户输入的 ID 与“CustomerID”字段匹配,则 RowFilter 设置为仅提取行的数据。如何遍历已添加的 Rows 以为行中的数据创建临时对象?
'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
【问题讨论】: