Crystal Reports XI Release 2  

Tutorial: Connecting to ADO.NET DataSets: Introduction

In this tutorial, you learn how to connect a Crystal report to an ADO.NET DataSet, through a DataSet schema. Some extra steps are required to report from an ADO.NET DataSet, because the report is not connected directly to a database.

An ADO.NET DataSet schema provides a template of the data structure in XML. However, a report cannot retrieve data from the DataSet schema alone. The DataSet schema must first be instantiated as a strongly-typed DataSet instance or as a generic DataSet instance. Then, the DataSet instance must be filled with data, through use of the DataAdapter classes.

In this tutorial, because of the added complexity that is involved in reporting from ADO.NET DataSets, the processes that you follow to create the schema and populate the DataSet are carefully kept separate from the Crystal Reports binding code.

Note   Visual Studio provides a template, named DataSet, to create an ADO.NET DataSet schema. In Visual Studio 2005 Web sites, the DataSet template is not accessible from the Add New Item dialog box. Only the default "XML Schema" template is available. However, with minor adjustments in the code (explained in the steps that follow), you can use the default template XML Schema to achieve the same results.

To begin, you create a data connection and build a DataSet schema that is based on that connection. You then create a helper class with a property that returns a populated instance of the DataSet. Finally, you write code that binds your Crystal report to the DataSet.

For the Crystal report binding code, you write code to do the following:

Finally, if you are building a Web Site, you place your populated DataSet instance into an ASP.NET Cache object, to improve performance and scalability.

It is recommended that you keep the DataSet configuration process and the Crystal report binding process distinct, both to maintain clarity in the code when you bind the report, and to promote reusability of the DataSet across your Web or Windows project.

Continue to Configuring a Connection to the Sample Database in the Server Explorer.

See Also

Tutorial: Connecting to ADO.NET DataSets | Tutorials and Sample Code | Tutorials' Sample Code Directory