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

问题描述 投票:0回答:1

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

crystal-reports dataset report datasource fill
1个回答
0
投票

这里我的代码使用2个表作者和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

记住你需要导入

Imports CrystalDecisions.CrystalReports.Engine导入CrystalDecisions.Shared

© www.soinside.com 2019 - 2024. All rights reserved.