为了把问题说清楚,说的哆嗦了点。
  现有数据库“收购进度.mdb”其中有数据表“收购进度表”,包含五个字段名“日期”,“单位”,“品种”,“数量”,“金额”。
  已定义连接MyConnection和记录集MyRecordset。窗体上有两个DTPicker控件,把它们分别赋值给两个DATE类型变量RQ1和RQ2。两个Textbox控件分别赋值给两个String类型变量DV和PZ。还有两个Single类型变量XL和JE用于存放汇总数据。
  现要对“收购进度表”进行查询,条件是“日期”字段>=RQ1且<=RQ2,“单位”字段=DV,“品种”字段=PZ。
  对查询结果的“数量”、“金额”字段进行合计,把值分别赋给XL和JE。
  我用ADO对象和数据库连接,请问怎样写。
  我的程序就差这一点了,麻烦高手们帮兄弟一把,感谢万分

解决方案 »

  1.   


    SqlStr="select sum(数量),sum(金额) from 收购进度表  where (日期 between" & RQ1 & "and " & RQ2 & ") and 单位='" & dv & "' and 品种='"pz &"' group by 品种 "myrecordest.open sqlstr,myconnection,adopendymanic,adlockbatchopeimisti
    xl=myrecordest.fields("数量").value
    je=myrecordest.fields(“金额").value
    应该是这样的了。问题是我的程序没有调试过,可能会出现错误,,不过总体思想应该是这样的
      

  2.   

    首先表示忠心的感谢,我现在就进行调试,如果可行,我会大大给分的。
    另外是否需要加一句:
    if not (myrecordset.bof and myrecordset.eof) then
        xl=myrecordset.fields("数量").value
        je=myrecordset.filds("金额").value
    endif
      

  3.   

    dim sum,cash as single
    sum=0
    cash=0SqlStr="select sum(数量),sum(金额) from 收购进度表  where (日期 between'" & RQ1 & "'and '" & RQ2 & "') and 单位='" & dv & "' and 品种='"& pz &"'"
    myrecordset.open sqlstr,3,2do while not myrecordset.eof
       sum=sum+数量
       cash=cash+金额
       myrecordset.movenext
    loop
    text.text=sum
    text1.text=cash
      

  4.   

    SqlStr=" select 品种,sum(数量) as fSumNum,sum(金额) as fSumMoney " _
         & " from   收购进度表 " _
         & " where  (日期 between # " & format(RQ1,"yyyy-mm-dd") & " # and # " _
                     & format(RQ2,"yyyy-mm-dd") & " #) and 单位='" & dv & "'" _
                     & " and 品种='"pz &"' group by 品种 "
    if myrecordset.state=adstateopen then myrecordset.close
    myrecordest.open sqlstr,myconnection,adopenkeyset,adlockreadonly
    if myrecordset.recordcount>0 then
        x1=myrecordset!fSumNum
        je=myrecordset!fSumMoney
    end if
    set myrecordset=nothing
      

  5.   

    SqlStr="select sum(数量),sum(金额) from 收购进度表  where (日期 between" & RQ1 & "and " & RQ2 & ") and 单位='" & dv & "' and 品种='"pz &"' group by 品种 "myrecordest.open sqlstr,myconnection,adopendymanic,adlockbatchopeimisti
    xl=myrecordest.fields(0).value
    je=myrecordest.fields(1).value