|
|
Title | Use Crystal Reports to build a PDF file in Visual Basic 2005 |
Description | This example shows how to use Crystal Reports to build a PDF file in Visual Basic 2005. |
Keywords | Crystal Reports, PDF file, report, VB.NET, Visual Basic 2005 |
Categories | Files and Directories, Miscellany |
|
|
First define a DataSet at design time. See the HowTo Define a DataSet at design time in Visual Basic 2005 for details.
Next add a new Crystal Report object to the project:
- Open the Project menu and select the Add New Item command.
- Select Crystal Report, give it a good name (such as AppointmentsReport.rpt), and click Add.
- Create a standard report by using the Report Wizard. On the wizard's Data page, open the "Project Data" entry and expand its "ADO.NET DataSets" item. Open the DataSet you created, select the table you want, and click the ">" button to select it as a data source for the report. Click Next.
- Use the ">>" button to add all of the table's fields to the report.
- Use the wizard's other pages to provide other report features such as Group By.
- When you finish, the wizard will create a report containing all of the fields in a simple layout.
You can modify the report if you wish to make it look nicer.
The example program uses the following code to populate a DataSet, attach it to the report, and save the report in a PDF file.
|
|
' Make a DataSet and add some records to it.
Dim ds As New PeopleDataSet()
ds.dtPeople.Rows.Add("Alice", "Archer", "111 Ash Ave", _
"Ashland", "KY", "11111", "111-111-1111")
ds.dtPeople.Rows.Add("Ben", "Butter", "222 Beach Blvd", _
"Bend", "OR", "22222", "222-222-2222")
ds.dtPeople.Rows.Add("Cindy", "Concert", "333 Cedar Ct", _
"Cinderblock", "NV", "33333", "333-3333")
' Create a new report and attach it to the DataSet.
Dim rpt As New AppointmentsReport()
rpt.SetDataSource(ds)
' Save the report in PDF format.
rpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, _
"test.pdf")
' Clean up.
rpt.Dispose()
ds.Dispose()
|
|
|
|
|
|