News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Use Crystal Reports to build a PDF file in Visual Basic 2005

Started by nandagopal, Nov 17, 2008, 07:21 PM

Previous topic - Next topic

nandagopal

Next add a new Crystal Report object to the project:

   1. Open the Project menu and select the Add New Item command.
   2. Select Crystal Report, give it a good name (such as AppointmentsReport.rpt), and click Add.
   3. 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.
   4. Use the ">>" button to add all of the table's fields to the report.
   5. Use the wizard's other pages to provide other report features such as Group By.
   6. 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()