由於DB為MYSQL資料庫是用ODBC來連接做水晶報表,預覽及Push模式下漢字都會是亂碼,所以偶採用Pull模式
偶在DB中有2張表,這兩張表之間都有一個欄位作共同的關聯,由於每張表筆數可能會有多筆,在用水晶報表處理時就要用到子報表
部分相關代碼如下:

 1Pull模式下的水晶子報表1/24private hierarchicalGroupingReport as reportdocument
 2Pull模式下的水晶子報表1/24dim dt1,dt2 as datatable
 3Pull模式下的水晶子報表1/24Pull模式下的水晶子報表1/24 
 4Pull模式下的水晶子報表1/24hierarchicalGroupingReport=new reportdocument
 5Pull模式下的水晶子報表1/24hierarchicalGroupingReport.Load(Server.MapPath("cr8202.rpt"))  
      hierarchicalGroupingReport.SetDataSource(dt)
 6Pull模式下的水晶子報表1/24
 7Pull模式下的水晶子報表1/24Dim crsections As Sections = hierarchicalGroupingReport.ReportDefinition.Sections
 8Pull模式下的水晶子報表1/24Dim crsection As Section
 9Pull模式下的水晶子報表1/24Dim crreportobjects As ReportObjects
10Pull模式下的水晶子報表1/24Dim crreportobject As ReportObject
11Pull模式下的水晶子報表1/24Dim crsubreportobject As SubreportObject
12Pull模式下的水晶子報表1/24Dim crsubreportdocument As ReportDocument = Nothing
13Pull模式下的水晶子報表1/24
14Pull模式下的水晶子報表1/24    For Each crsection In crsections
15Pull模式下的水晶子報表1/24             crreportobjects = crsection.ReportObjects
16Pull模式下的水晶子報表1/24                For Each crreportobject In crreportobjects
17Pull模式下的水晶子報表1/24                     If crreportobject.Kind = ReportObjectKind.SubreportObject Then
18Pull模式下的水晶子報表1/24                  crsubreportobject = CType(crreportobject, SubreportObject)            
  crsubreportdocument = crsubreportobject.OpenSubreport(crsubreportobject.SubreportName)
19Pull模式下的水晶子報表1/24                                crsubreportdocument.SetDataSource(dt1)
20Pull模式下的水晶子報表1/24                      End If
21Pull模式下的水晶子報表1/24                 Next
22Pull模式下的水晶子報表1/24     Next
23Pull模式下的水晶子報表1/24
24Pull模式下的水晶子報表1/24
25Pull模式下的水晶子報表1/24crsubreportdocument.Dispose()
26Pull模式下的水晶子報表1/24dt1.dispose()
27Pull模式下的水晶子報表1/24dt2.dispose()
       page_unload事件中:
28Pull模式下的水晶子報表1/24hierarchicalGroupingReport.dispose()'此句可以解除或者避免VS2005下水晶報表連續使用次數限制
還有一點要補充的,子報表中顯示的欄位如果秀不出來,請改用公式欄位Pull模式下的水晶子報表1/24

相关文章: