Customers.CustomerID = Orders.CustomerID

Notice in Figure 7-30 how OleDbConnection1 has also appeared on the report next to OleDbDataApdapter1. This is generated from the connection information that you provided the Data Adapter Configuration Wizard.

Figure 7-30

With the form now set up to access the dataset, we need to look at some code. Add the same namespaces as we did to view the dataset earlier in this chapter. In addition, because we will be printing a report based on this data, we need to add the CrystalDecisions.CrystalReports.Engine namespace to the code behind this form, as shown here:

Imports System.Data Imports System.Data.OleDb

Imports CrystalDecisions.CrystalReports.Engine

Public Class Forml

Inherits System.Windows.Forms.Form

Next we need to add variables to dimension the connection, the data adapter, and the dataset, and get the form ready to accept data. We will connect to the Northwind database using OleDbConnectionl (as seen on the form designer), and submit an SQL query that will return a result set, filling the Customers table, and then the Orders table in the dataset. To do this, double-click the CrystalReportViewer in the Form Designer to generate the CrystalReportViewer1_Load procedure. Then insert the following code:

Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object,

ByVal e As System.EventArgs) Handles CrystalReportViewerl.Load

Dim myDataSet = New CustomerOrders()

Dim sqlString As String = "Select * from Customers"

OleDbDataAdapterl = New OleDbDataAdapter(sqlString, OleDbConnectionl) OleDbDataAdapter1.Fill(myDataSet, "Customers")

sqlString = "Select * from Orders"

OleDbDataAdapterl = New OleDbDataAdapter(sqlString, OleDbConnectionl) OleDbDataAdapter1.Fill(myDataSet, "Orders")

End Sub

With the data now in the dataset, we can set our report source and preview the report itself, by adding this code to the bottom of the CrystalReportViewer1_Load procedure:

OleDbDataAdapter1.Fill(myDataSet, "Orders")

Dim myReport = New adonet_sample() myReport.SetDataSource(myDataSet) CrystalReportViewerl.ReportSource = myReport

End Sub

When you run your application and view this form, your report will be filled with data from the ADO .NET dataset, and will be displayed within the viewer.

The only difference in integration between the Windows and the Web Crystal Report Viewer is that you will need to add the appropriate report viewer for the environment you are working with (discussed in Chapter 4, "Report Integration for Windows-Based Applications," and Chapter 5, "Report Integration for Web-Based Applications"). You can change the contents of the ADO .NET dataset numerous times within your application, and you can call the DataSource method at any time before previewing or refreshing your report.

Was this article helpful?

0 0

Post a comment