如何用VB.NET做水晶报表?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用VB.NET做水晶报表?相关的知识,希望对你有一定的参考价值。

CrystalReportViewer
dataset 定义数据源
.rpt 文件描述具体报表样式
再加一个调用报表的FORM,就可以实现简单的报表功能
Option Explicit
dim Report as New Cystal1

Private Sub Form_Load()

 Screen.MousePointer = vbHourglass
 '调用水晶报表时置鼠标为沙漏状 CRViewer91.ReportSource = Report '该语句的赋值将在后面被修改

 CRViewer91.ViewReport
 Screen.MousePointer = vbDefault '调用水晶报表完成后置鼠标为默认形状

End Sub

Private Sub Form_Resize()

 CRViewer91.Top = 0
 CRViewer91.Left = 0
 CRViewer91.Height = ScaleHeight
 CRViewer91.Width = ScaleWidth

End Sub
参考技术A 第一步:连接数据库;
第二步:利用crystalreportviewer和reportdocument控制进行数据绑定;

第三步:编写代码
其实做报表的话,个人觉得水晶报表比较麻烦,不及finereport更快更简单。

来自数据集的 Vb.Net 水晶报告

【中文标题】来自数据集的 Vb.Net 水晶报告【英文标题】:Vb.Net crystal report from dataset 【发布时间】:2014-01-16 17:58:07 【问题描述】:

我正在使用 Vb.Net 2010 开发具有水晶报表的项目。我连接到 sqlserver 并使用函数 Adapter.Fill(dataset,"tableName") 填充我的数据集。我现在关心的是如何在水晶报表中显示我的数据集或数据表中的数据?

【问题讨论】:

【参考方案1】:

这里我的代码使用 2 个表 authors 和 titleauthor

'Build a SQL statement to query for the authors table 

Dim sqlString As String = "SELECT * FROM authors"

'Retrieve the data using the SQL statement 

adoOleDbDataAdapter = New OleDbDataAdapter(sqlString, adoOleDbConnection)

'Build a SQL statement to query for the titleauthor table 

sqlString = "SELECT * FROM titleauthor" 

'Retrieve the data using the SQL statement 

adoOleDbDataAdapter2 = New OleDbDataAdapter(sqlString, adoOleDbConnection) 

'Create a instance of a Dataset 

DataSet1 = New DataSet() 

'Fill the dataset with the data with author information 

adoOleDbDataAdapter.Fill(DataSet1, "authors") 

'Fill the dataset with the data with titleauthor information. 
'The table name used in the Fill method must be identical to the name 
'of the table in the report. 

adoOleDbDataAdapter2.Fill(DataSet1, "titleauthor") 

'Pass the dataset to the report   YOU NEED THIS

Dim crReportDocument As New CrystalReport1()


crReportDocument.Database.Tables(0).SetDataSource(DataSet1) 

'View the report 

CrystalReportViewer1.ReportSource = crReportDocument

记住你需要导入

导入 CrystalDecisions.CrystalReports.Engine 导入 CrystalDecisions.Shared

【讨论】:

以上是关于如何用VB.NET做水晶报表?的主要内容,如果未能解决你的问题,请参考以下文章

VB.net中如何制作水晶报表?

如何使用 vb.net 将 sql 值设置为水晶报表参数

来自数据集的 Vb.Net 水晶报告

使用物理路径在水晶报表中显示图像

使用数据库专家在水晶报表上添加表格:登录失败

怎么使用和创建水晶报表 子报表?