Crystal Reports Without Database

Crystal Reports is commonly utilized to retrieve data from databases and present it in the form of a report. However, in this particular scenario, we will demonstrate how to generate a Crystal Reports document without relying on a traditional database. Instead, we will employ a Strongly Typed Dataset and a Data Table to achieve this.

Before investigating into the specifics of generating a Crystal Reports document without a database, it is recommended to familiarize yourself with the fundamentals of Crystal Reports creation. To acquire a comprehensive understanding, please refer to the previous section of this tutorial, which provides a step by step Crystal Report guide on creating Crystal Reports.

Generating a Strongly Typed DataSet

Create a new VB.NET Project and accept the default settings. Create a new Dataset from Project - Add New Item Dialogue Box.

vb.net_crystal_report_without_database_1.GIF

Accept the default name DataSet1.xsd .

Create a data table for DataSet1.xsd .

Select DataSet1.xsd from Solution Explorer and right click . Select datatable from the menu. Then you will get a datatable in the Datast . Right click the datatable and select Add-Column.

vb.net_crystal_report_without_database_2.GIF

Here we are making a two column Crystal Reports , so we need two column in the data table . Add and ID column and Name column in the Data Table.

vb.net_crystal_report_without_database_3.GIF

The dataset portion has been completed. The subsequent step entails creating a Crystal Reports document based on this dataset. Before proceeding with the Crystal Reports design, it is highly recommended to refer to the step-by-step Crystal Report guide, which provides a straightforward approach to creating Crystal Reports.

To initiate the process, select "Add New Item" from the menu and choose "Crystal Reports" as the new item. Accept the default settings for the Crystal Reports configuration. The following screen prompts you to select the appropriate data source. From the "Project data - ADO.NET Datasets" section, locate "Datatable1" and choose it by moving it to the right-hand side.

vb.net_crystal_report_without_database_4.GIF

Click Next button and select ID and Name from the datatable1 to right side and click finish.

vb.net_crystal_report_without_database_5.GIF

Now the Crystal Reports designer part is over . Next part is to create data for the Crystal Reports . For that we have to create a Data Table through programmatically and add data to dataset1.

Select the default form (Form1.vb) you created in VB.NET and drag one button and CrystalReportViewer control to your form.

Put the following source code in the button click events

Full Source VB.NET
Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Imports System.Data Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim ds As New DataSet1 Dim t As DataTable = ds.Tables.Add("Items") t.Columns.Add("id", Type.GetType("System.Int32")) t.Columns.Add("Item", Type.GetType("System.String")) Dim r As DataRow Dim i As Integer For i = 0 To 9 r = t.NewRow() r("id") = i r("Item") = "Item" & i t.Rows.Add(r) Next Dim objRpt As New CrystalReport1 objRpt.SetDataSource(ds.Tables(1)) CrystalReportViewer1.ReportSource = objRpt CrystalReportViewer1.Refresh() End Sub End Class