在for循环中如何增加数据表中的行

时间:2011-05-03 02:10:04

标签: vb.net

在for循环中如何增加到下一行并在if条件不满足时添加新成员。

例如。

for i ...to ..row.count
 if condition to compare...if member exists then ....
( not Met ) 
increment the row in the data table and (goto)
else
( add a new member to a new row in datatable)
endif

next

2 个答案:

答案 0 :(得分:0)

如何在不同的集合上循环 - 数据表中的行:

Dim i as Integer = 0
Dim row as DataRow
For Each row in myDataTable
    If (condition) Then
    'do something
    Else
    'something else
    End If
    'in case you need to keep a counter
    i = i + 1 
End

答案 1 :(得分:0)

我不是百分百肯定我理解;但我觉得.... 您将无法使用 For Each 来访问行并修改集合。

最明确的方法是使用While循环。

Dim i as Integer = 0 
While i < myDataTable.Rows.Count
    ' Your If statement here
End While