Share via


Tutorial: Connecting to IDataReader

Introduction

Many .NET projects use DataReader, rather than DataSet, to retrieve data. For example, a typical way to bind a control (such as the GridView control) to data is to create a method that retrieves data through a DataReader, and then return that data from the method through an IDataReader interface.

In Crystal Reports for Visual Studio, the embedded Crystal Report Designer can access IDataReader, provided certain conditions are met:

  • The data must be returned from a method, through the IDataReader interface.

  • The data provider that is used within the method must be the OleDb .NET data provider.

    Note

    The classes for this data provider are located in the System.Data.OleDb namespace.

  • The method must be Shared [Visual Basic] or static [C#].

  • The class that contains this method must be part of a class library project and be compiled into an assembly.

In this tutorial, you learn how to connect a Crystal report to the DLL assembly file, and how to access a class and static method within the assembly that returns the IDataReader.

To begin, you create a class library, add a class and a static method that returns IDataReader, and then compile that class library into an assembly.

Sample Code

This tutorial comes with Visual Basic and C# sample code that show the completed version of the project. Follow the instructions in this tutorial to create a new project or open the sample code project to work from a completed version.

The sample code is stored in folders that are categorized by language and project type. The folder names for each sample code version are as follows:

  • C# Web Site: CS_Web_Data_IDataReader
  • C# Windows project: CS_Win_Data_IDataReader
  • Visual Basic Web Site: VB_Web_Data_IDataReader
  • Visual Basic Windows project: VB_Win_Data_IDataReader

To locate the folders that contain these samples, see Tutorials' Sample Code Directory.

In this section: