CSharp.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  C# Crystal Reports without database

Usually we are using Crystal Reports to fetch data from databases and show it as a report. Here we are generating a Crystal Reports from C# without using a database . For generating a Crystal Reports without database , here we are using a Strongly Typed Dataset and a Data Table of C#.

If you are new to Crystal Reports and do not know how to create Crystal Reports from C# , please take a look at the section step by step tutorial for creating a Crystal Reports from C#.

Generating a Strongly Typed DataSet

Create a new C# Project and create a Dataset from Project - Add New Item Dialogue Box.

csharp-crystal-report-add-new

Select Dataset from list

csharp-crystal-report-dataset

Accept the default name DataSet1.xsd .

Create a data table for DataSet1.xsd in C#.

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 .

csharp-crystal-report-add-column

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

csharp-crystal-report-id-item

Now the dataset part is over . Next step is to create a Crystal Reports from the Dataset we created. Select a new Crystal Reports from Add New Item menu and accept the default settings. The next screen is to select appropriate data source . There you can find the Datatable1 from Project data - ADO.NET Datasets , and select Datatable1 to the right side.

csharp-crystal-report-datatable-select

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

csharp-crystal-report-datatable-items

Now the C# 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.cs) you created in C# and drag a button and a CrystalReportViewer control to your form .

Copy and paste the following source code and run your C# project

         C# Source Code Download           Print Source Code
         C# Crystal Reports without database - Download
        
C# Tutorial

using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataSet1 ds = new DataSet1();
            DataTable t = ds.Tables.Add("Items");
            t.Columns.Add("id", Type.GetType("System.Int32"));
            t.Columns.Add("Item", Type.GetType("System.String"));

            DataRow r ;
            int i = 0;
            for (i = 0; i <= 9; i++)
            {
                r = t.NewRow();
                r["id"] = i;
                r["Item"] = "Item" + i;
                t.Rows.Add(r);
            }

            CrystalReport1 objRpt = new CrystalReport1();
            objRpt.SetDataSource(ds.Tables[1]);
            crystalReportViewer1.ReportSource = objRpt;
            crystalReportViewer1.Refresh(); 
        }
    }
}



C# Crystal Reports Related Contents
*     C# Crystal Reports sample databse
*     C# Crystal Reports step by step
*     C# Crystal Reports from multiple tables
*     C# Crystal Reports String parameter
*     C# Crystal Reports Integer parameter
*     C# Crystal Reports Date parameter
*     C# Crystal Reports Dynamic Logon parameters
*     C# Crystal Reports Formula Field
*     C# Crystal Reports Summary Field
*     C# Crystal Reports Export to Pdf
*     C# Crystal Reports Export to Excel
*     Email Crystal Reports from C# Application
*     C# Crystal Reports from SQL Query
*     Dynamic Crystal Reports from C# Application
*     C# Crystal Reports from XML
*     C# Crystal Reports - sub reports
*     C# Crystal Reports - on demand sub reports
*     C# Crystal Reports - Date to Date
*     How to print Crystal Reports in C#
*     How to deploy Crystal Report
*     How to Crystal Report Merge Module
*     5 Tests for Top Performance by Jason Dove
*     3 New Uses For Sub Reports by Jason Dove


   Home      VB.NET      C#
CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
*     C# DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.