高级交叉报表例子程序(C#)中明细列统计数据错误改正!

问题出现在红色代码处:
    
int CurProductID = (int)odr["Productid"];
    while (CurProductID == (int)odr["Productid"])
    {
     DateTime dt = (DateTime)odr["OrderDate"];

     int FieldIndex = SumByMonth? (dt.Month-1) : (dt.Month-1) / 3;
     Report.DetailGrid.Recordset.Fields[m_AmtFieldIndexs[FieldIndex]].AsFloat += (double)odr["Amount"];
     Report.DetailGrid.Recordset.Fields[m_QtyFieldIndexs[FieldIndex]].AsInteger += (int)(Int16)odr["Quantity"];

     if ( !odr.Read() )
      break;
    }
经斑竹修改后:
private void ReportFetchRecord(ref bool Eof)
  {
   OleDbConnection ocnnNorthwind = new OleDbConnection(GridppReportDemo.Utility.GetDatabaseConnectionString());
   OleDbCommand ocmd = new OleDbCommand("select d.Productid,p.ProductName,m.OrderDate,d.Quantity,d.UnitPrice*d.Quantity*(1-d.Discount) as Amount "
    + "from orders m inner join ([Order Details] d inner join Products p on d.ProductID=p.ProductID) "
    + "on m.orderid=d.orderid "
    + "where m.OrderDate between #1/1/97# And #12/31/97# "
    + "order by d.Productid,m.OrderDate", ocnnNorthwind);
   ocnnNorthwind.Open();
   OleDbDataReader odr = ocmd.ExecuteReader(CommandBehavior.CloseConnection);

   int DataGroupCount = SumByMonth? 12 : 4;
   int CurProductID = -1; //(int)odr["ProductID"];
   while ( odr.Read() )
   {
    if (CurProductID != (int)odr["ProductID"])
    {
     //提交上一笔数据
     if (CurProductID > 0)
      Report.DetailGrid.Recordset.Post();

     Report.DetailGrid.Recordset.Append();

     //设初值
     for (int i=0; i<DataGroupCount; ++i)
     {
      ((IGRField)m_pAmtFields[i]).AsFloat = 0;
      ((IGRField)m_pQtyFields[i]).AsFloat = 0;
     }
     m_pProductIDField.Value = odr["ProductID"];
     m_pProductNameField.Value = odr["ProductName"];

     CurProductID = (int)odr["ProductID"];
    }

    DateTime dt = (DateTime)odr["OrderDate"];
    int FieldIndex = SumByMonth? (dt.Month-1) : (dt.Month-1) / 3;
    ((IGRField)m_pAmtFields[FieldIndex]).AsFloat += (double)odr["Amount"];
    ((IGRField)m_pQtyFields[FieldIndex]).AsInteger += (int)(Int16)odr["Quantity"];
   }

   //提交最后一笔数据
   Report.DetailGrid.Recordset.Post();

   odr.Close();
  }

http://www.rubylong.cn/bbs/dispbbs.asp?boardID=8&ID=4699&page=1

转载于:https://www.cnblogs.com/Godblessyou/archive/2007/12/17/1003453.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值