dim i as interger
rs.open"select ma001 as t1,ma002 as t2 from mocta where ta001='"str"'", cndb, adOpenStatic, adLockOptimistic
set datareport2.datasource=rs
do while not rs.eofi=format(val(rs.fields("t2"))*1.04,"0.00")
DataReport2.Sections("Section1").Controls("品号").caption= "T1"
datareport2.Sections("Section1").Controls("数量").caption=i
DataReport2.Sections(1).ForcePageBreak = rptPageBreakAfter
adodcnset.MoveNext
loop
datareport2.show
我利用RS访问数据库其品号、数量栏位,条件为“str”,访问结果是
品   号    数  量
A0001            10000
A0002            20000通过datareport2打印出来,记录数几条,就列印几张,列印没有问题, 就是数理显示的结果有错
本应列出结果如下:
品号    数量
A0001      10400  (10000*1.04)
A0002      20800  (20000*1.04)但是显示结果为:
品号    数量
A0001     20800   (20000*1.04)
A0002     20800   (20000*1.04)
也就是说,数量这一栏位不会自动更新,总是显示最后一笔访问的记录结果,为什么品号栏不会这种问题呢。请各位帮帮忙

解决方案 »

  1.   

    当然啦,你用的是caption,只显示一个字符串你应该用字段
    rs.open"select ma001 as t1,ma002 as t2,round(ma002 *1.04) as i from mocta where ta001='"str"'", cndb, adOpenStatic, adLockOptimistic
    set datareport2.datasource=rsDataReport2.Sections("Section1").Controls("品号").datafield= "T1"
    datareport2.Sections("Section1").Controls("数量").datafield="i"
      

  2.   

    feiyun0112(http://feiyun0112.cnblogs.com/) ( ) 信誉:100 
    谢谢楼上的兄弟了,可以了。
    我现在要在一个datareport报表中,设置两个datasource记录。该怎么办
    s.open"select ma001 as t1,ma002 as t2,round(ma002 *1.04) as i from mocta where ta001='"str"'", cndb, adOpenStatic, adLockOptimistic
    set datareport2.datasource=rs
    DataReport2.Sections("Section1").Controls("品号").datafield= "T1"
    datareport2.Sections("Section1").Controls("数量").datafield="i"、
    adodcnset,open"select CB001 AS T3,CB002 AS T2 FROM MOCCB WHERE CB001='"STR"'",CNDB,ADOPENSTATIC,ADLOCKOPTIMISTIC
    请问:我该如何将"T3"赋值给datareport2.Sections("Section1").Controls("规格").datafield
    谢谢 
      

  3.   

    只能用一个datasource用join 放到一起
    select a.ma001 as t1,a.ma002 as t2,round(a.ma002 *1.04) as i,b.CB001 AS T3 from mocta a 
    inner join MOCCB  b on a.ma002 =b.CB002 
    where a.ta001='str' and b.CB001='str' 
    我假定ma002=CB002 ,按你的世纪关系写