Bind the Dataset to the report
The last step in using the Push Model is writing the code to link the fully populated dataset to the report. The ReportDocument class has a SetDataSource() method that takes a populated DataSet object and uses it as the data source for the report. After calling this method the report is bound to the dataset and is able to print the records.
Dim myReport as New CrystalReport1
Dim myDataSet As New DataSet()
'Use the appropriate FillDataSet() method from the previous section
FillDataSet(myDataSet)
'Uncomment the following line if you need to create a new dataset file
'CreateXmlFile("C:\FileName.ds", myDataSet)
myReport.SetDataSource(myDataSet)
CrystalReportViewer1.ReportSource = myReport
The code first creates an instance of the report and assigns it to the myReport object variable. Then it creates a new DataSet object and passes it to the FillDataSet() method. This method is from the code listings in the prior section. Use the one that matches your data source and modify it for any special needs you have. There is also a call to the procedure WriteXmlFile() and it is commented out. As mentioned earlier, before you build a report you need to have a dataset file that the report can reference. It is commented out so that you can run it again if you need to rebuild the dataset file.
The SetDataSource() method is passed the populated dataset. This binds the data to the report.