for循环中的多个if语句

时间:2014-01-28 17:56:17

标签: vb.net loops if-statement for-loop

请帮助,下面是我在Visual Basic中的代码。

我的for循环没有进入第二个if条件。它只是检查第一个。我在这里缺少什么?

谢谢!

If Not dsMarketingOrdIDs Is Nothing Then
    For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1
        If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 Then
            If Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") Then
                blnKbAuthorXtremeSupport = True
            End If
            If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152 Then
                If Not objALUtil.CheckPermission("KBAUTHORXTREMEPORTAL") Then
                    blnKbAuthorXtremePortal = True

                End If
            End If
        End If
    Next
End If

2 个答案:

答案 0 :(得分:1)

应该是这样的:

If Not dsMarketingOrdIDs Is Nothing Then
    For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1
        If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 Then
            If Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") Then
                blnKbAuthorXtremeSupport = True
            End If
        End If
        If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152 Then
            If Not objALUtil.CheckPermission("KBAUTHORXTREMEPORTAL") Then
                blnKbAuthorXtremePortal = True
            End If
        End If
    Next
End If

甚至更容易:

If Not dsMarketingOrdIDs Is Nothing Then
    For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1
        blnKbAuthorXtremePortal = Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") _
            AndAlso (dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 OrElse dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152)
    Next
End If

答案 1 :(得分:0)

你有没有试过别的?

If Not dsMarketingOrdIDs Is Nothing Then
    For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1
        If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 Then
            If Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") Then
                blnKbAuthorXtremeSupport = True
            Else If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152 Then
                If Not objALUtil.CheckPermission("KBAUTHORXTREMEPORTAL") Then
                    blnKbAuthorXtremePortal = True
                End If
            End If
        End If
    Next
End If

另外,您的MARKETING_ORG_ID如何同时为5和152?

dtMarketingOrdIDs.Rows(i)(“marketing_org_id”)= 5

dtMarketingOrdIDs.Rows(i)(“marketing_org_id”)= 152