相忘于江湖

不抛弃,不放弃... 请给我勇敢,改变可以改变的;请给我坚强,接受不可以改变的;请给我智慧,分辨这两者。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

问题出现在红色代码处:
    
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
posted on 2007-12-17 18:17  playman0211  阅读(515)  评论(0编辑  收藏  举报