由於DB為MYSQL資料庫是用ODBC來連接做水晶報表,預覽及Push模式下漢字都會是亂碼,所以偶採用Pull模式
偶在DB中有2張表,這兩張表之間都有一個欄位作共同的關聯,由於每張表筆數可能會有多筆,在用水晶報表處理時就要用到子報表
部分相關代碼如下:
1private hierarchicalGroupingReport as reportdocument
2dim dt1,dt2 as datatable
3
4hierarchicalGroupingReport=new reportdocument
5hierarchicalGroupingReport.Load(Server.MapPath("cr8202.rpt"))
hierarchicalGroupingReport.SetDataSource(dt)
6
7Dim crsections As Sections = hierarchicalGroupingReport.ReportDefinition.Sections
8Dim crsection As Section
9Dim crreportobjects As ReportObjects
10Dim crreportobject As ReportObject
11Dim crsubreportobject As SubreportObject
12Dim crsubreportdocument As ReportDocument = Nothing
13
14 For Each crsection In crsections
15 crreportobjects = crsection.ReportObjects
16 For Each crreportobject In crreportobjects
17 If crreportobject.Kind = ReportObjectKind.SubreportObject Then
18 crsubreportobject = CType(crreportobject, SubreportObject)
crsubreportdocument = crsubreportobject.OpenSubreport(crsubreportobject.SubreportName)
19 crsubreportdocument.SetDataSource(dt1)
20 End If
21 Next
22 Next
23
24
25crsubreportdocument.Dispose()
26dt1.dispose()
27dt2.dispose()
page_unload事件中:
28hierarchicalGroupingReport.dispose()'此句可以解除或者避免VS2005下水晶報表連續使用次數限制
還有一點要補充的,子報表中顯示的欄位如果秀不出來,請改用公式欄位
2dim dt1,dt2 as datatable
3
4hierarchicalGroupingReport=new reportdocument
5hierarchicalGroupingReport.Load(Server.MapPath("cr8202.rpt"))
hierarchicalGroupingReport.SetDataSource(dt)
6
7Dim crsections As Sections = hierarchicalGroupingReport.ReportDefinition.Sections
8Dim crsection As Section
9Dim crreportobjects As ReportObjects
10Dim crreportobject As ReportObject
11Dim crsubreportobject As SubreportObject
12Dim crsubreportdocument As ReportDocument = Nothing
13
14 For Each crsection In crsections
15 crreportobjects = crsection.ReportObjects
16 For Each crreportobject In crreportobjects
17 If crreportobject.Kind = ReportObjectKind.SubreportObject Then
18 crsubreportobject = CType(crreportobject, SubreportObject)
crsubreportdocument = crsubreportobject.OpenSubreport(crsubreportobject.SubreportName)
19 crsubreportdocument.SetDataSource(dt1)
20 End If
21 Next
22 Next
23
24
25crsubreportdocument.Dispose()
26dt1.dispose()
27dt2.dispose()
page_unload事件中:
28hierarchicalGroupingReport.dispose()'此句可以解除或者避免VS2005下水晶報表連續使用次數限制
還有一點要補充的,子報表中顯示的欄位如果秀不出來,請改用公式欄位