Vb.Net crystal report from dataset

主宰稳场 提交于 2019-12-12 04:38:32

问题


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?


回答1:


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

Remember you need to import

Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared



来源:https://stackoverflow.com/questions/20829545/vb-net-crystal-report-from-dataset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!