if rs.fields("商品")='礼品' then 改成if rs.fields("商品")="礼品" then

解决方案 »

  1.   

    cn.open str
    rs.Open str, cn, adOpenStatic
    If rs.RecordCount <> 0 Then
            With ListView1
                ListView1.ColumnHeaders.Add , , "日期", 1300
                ListView1.ColumnHeaders.Add , , "号码", 2000, 2
                ListView1.ColumnHeaders.Add , , "商品", 2000, 2
                For j = 0 To rs.RecordCount - 1            
                    if strNumber=rs.fields("号码") then
                        if rs.fields("商品")='礼品' then
         itemx.Subitems(2)="" '这里的本意是如果商品是礼品的话,该栏位就完全显示为空,不再循环后面的号码
                                                  '但是事实是不行的,如何改呢?
      exit for     
    else
                         itemx.SubItems(2) = itemx.SubItems(2) & "," & Trim(rs.Fields("商品"))
        end if
                    else
                        itemx.SubItems(0) = itemx.SubItems(0) & "," & Trim(rs.Fields("日期"))
                        itemx.SubItems(1) = itemx.SubItems(1) & "," & Trim(rs.Fields("号码"))
        itemx.SubItems(2) = itemx.SubItems(2) & "," & Trim(rs.Fields("商品"))
                    end if   
                next j
    end Listview1
    ...
    end if
      

  2.   

    if rs.fields("商品")='礼品' then ..
    if rs.fields("商品")="礼品" thenitemx.Subitems(2)=" " '加个空格试试
    '这里的本意是如果商品是礼品的话,该栏位就完全显示为空,不再循环后面的号码
    '但是事实是不行的,如何改呢?
    exit for     
      

  3.   

    如果后面的还要接着显示
    if rs.fields("商品")=“礼品” then
        itemx.Subitem2=""
    else
       if itemx.Subitem2<>"" then
          itemx.SubItems(2) = itemx.SubItems(2) & "," & fields(2)
       end if
    end if如果后面的不要显示
    if rs.fields("商品")=“礼品” then
        itemx.Subitem2=""
        exit for
    else
       itemx.SubItems(2) = itemx.SubItems(2) & "," & fields(2)
    end if
      

  4.   

    问题是循环是多重的呀,比如
    if rs.fields("商品")=“礼品” then
        for j=0 ro rs.recordcount -1
           itemx.Subitem2=""
           exit for '那么你这个exit for是退出那一个循环呢,显然不对!
        next j
    else
       itemx.SubItems(2) = itemx.SubItems(2) & "," & fields(2)
    end if
      

  5.   

    break
    试一下可以达到目的么???
      

  6.   

    那你就先定义一个Boolean变量,当内层循环要退出时,将此变量设为TRUE,在内层NEXT语句后面做一个判断,如果该变量为TRUE就再次EXIT FOR,退出外层循环