高级交叉报表例子程序(C#)中明细列统计数据错误改正!
問題出現(xiàn)在紅色代碼處:
????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;
????}
經(jīng)斑竹修改后:
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"])
????{
?????//提交上一筆數(shù)據(jù)
?????if (CurProductID > 0)
??????Report.DetailGrid.Recordset.Post();
?????Report.DetailGrid.Recordset.Append();
?????//設(shè)初值
?????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"];
???}
???//提交最后一筆數(shù)據(jù)
???Report.DetailGrid.Recordset.Post();
???odr.Close();
??}
轉(zhuǎn)載于:https://www.cnblogs.com/Godblessyou/archive/2007/12/17/1003453.html
總結(jié)
以上是生活随笔為你收集整理的高级交叉报表例子程序(C#)中明细列统计数据错误改正!的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Silverlight学习笔记之文字特效
- 下一篇: 关于网络打印机