来自数据集的Vb.Net水晶报告 [英] Vb.Net crystal report from dataset

查看:207
本文介绍了来自数据集的Vb.Net水晶报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Vb.Net 2010 to develop project that has crystal reports. I connect to sqlserver and fill my dataset using the function Adapter.Fill(dataset,"tableName"). My concern now is how can I display the data in my dataset or datatable in crystal report?

推荐答案

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

here my code using 2 tables authors and 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

Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared

这篇关于来自数据集的Vb.Net水晶报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆