1
Me.AdoCRViewer.DisplayToolbar = True
2
Me.AdoCRViewer.ShowExportButton = True
3
Me.AdoCRViewer.ShowCloseButton = True
4
Me.AdoCRViewer.ShowGotoPageButton = True
5
Me.AdoCRViewer.ShowPageNavigateButtons = True
6
Me.AdoCRViewer.ShowPrintButton = True
7
Me.AdoCRViewer.ShowRefreshButton = True
8
Me.AdoCRViewer.ShowTextSearchButton = True
9
Me.AdoCRViewer.ShowZoomButton = True
10
'/////// 设置显示样式
11
Me.AdoCRViewer.DisplayGroupTree = False
12
Me.AdoCRViewer.Dock = DockStyle.Fill
13
Me.AdoCRViewer.Zoom(110)
14
Me.AdoCRViewer.ShowFirstPage()
15
16
'设置Button1命令控件的属性
17
Me.AdoButton.Dock = DockStyle.Bottom
18
19
'取得ADO.NET中的数据集
20
'/////// 获取数据库CrystalReport.mdb的文件路径
21
Dim FilePath As String
22
FilePath = System.Reflection.Assembly.GetExecutingAssembly.Location()
23
FilePath = Microsoft.VisualBasic.Left(FilePath, InStr(FilePath, "\AdoReport"))
24
'/////// 连接数据源
25
Dim ConnectionString As String
26
ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath & "CrystalReport.mdb"
27
Dim connstr As New String(ConnectionString)
28
Dim searchSql As New String("select * from 产品资料")
29
'/////// 取得数据集
30
Dim da As New OleDbDataAdapter(searchSql, connstr)
31
Dim dsDatab As New DataSet
32
da.Fill(dsDatab)
33
34
35
'创建报表文件
36
'/////// 根据ProductInfo.rpt模版创建报表文件
37
Dim MyReportDoc As New ReportDocument
38
MyReportDoc.Load(FilePath & "\AdoReport\ProductInfo.rpt")
39
'/////// 设置报表文件的数据集
40
MyReportDoc.SetDataSource(dsDatab.Tables(0))
41
42
'为Crystal Report Viewer报表查看器控件设置报表文件
43
Me.AdoCRViewer.ReportSource = MyReportDoc
44
45
'消除创建的对象
46
da.Dispose()
47
dsDatab.Dispose()
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47