【问题标题】:How do I loop through the rows in a Dataview in vb.net如何遍历 vb.net 中 Dataview 中的行
【发布时间】: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

【问题讨论】:

    标签: vb.net rows dataview


    【解决方案1】:

    DataView 本身就是一个列表;准确地说是DataRowView 对象的列表。您只需遍历 DataView 本身,例如

    For Each row As DataRowView In myDataView
        Dim name = CStr(row("Name"))
        '...
    Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      • 2012-11-08
      相关资源
      最近更新 更多