Click here to Skip to main content
13,094,732 members (93,383 online)
Click here to Skip to main content
Add your own
alternative version


39 bookmarked
Posted 2 Jun 2005

How to use Crystal Reports with Access database in C#

, 2 Jun 2005
Rate this:
Please Sign up or sign in to vote.
An article explaining how to add reports to your home database in your C# application.


There are many ways to present data to users. For example, you can write code to loop through records and print them inside your Windows form. However, to do such a code any work beyond basic formatting can be very complicated to program. With Crystal Reports, you can quickly create complex and professional reports. Instead of writing code, you can use Crystal Report Designer interface to create and format reports. Its powerful engine processes the formatting, grouping, and charting criteria that you specify.


I’ve searched well so many sites about code that I can with the help of it, use Crystal Reports to connect to an Access database in a C# application. After searching C# books, I’ve found some nice code that helps me to create this simple application. Hope it can help as a basic architecture.

Using the code

At first, you should simply open VS.NET and then at the File menu, click on New, Project. From the New Project dialog box, choose the Windows Application template project and name it Crystal Report, like shown below:

After creating a window, add to it a Crystal Report Viewer control from the toolbox and dock the control to fit all the windows like shown below:

Select Add New Item from Project menu, click Crystal Report and finally click Open to invoke the Crystal Report Designer as shown below:

Use the Report Expert option and choose a template. For more information about each template, see the MSDN.

Now you should choose the data source as below:

Select Database Files, a dialog box will appear to select the location of the data source. After selecting the data source, insert the table that you want and click Next.

Add the fields you want to report and click Next. On the Chart tab, select the type of chart you want. And click Finish.

Note: You can go to the next steps to specify more options.

Now back to the Windows form. Go to the options of Crystal Report Viewer and specify the ReportSource as the .rpt file that you added in the previous step.

Full code

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Crystal_Report
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
        private CrystalDecisions.Windows.Forms.CrystalReportViewer 
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
            // Required for Windows Form Designer support

            // TODO: Add any constructor code after InitializeComponent call

       /// <summary>
       /// Clean up any resources being used.
       /// </summary>
       protected override void Dispose( bool disposing )
               if( disposing )
                       if (components != null) 
               base.Dispose( disposing );

       #region Windows Form Designer generated code
       /// <summary>
       /// Required method for Designer support - do not modify
       /// the contents of this method with the code editor.
       /// </summary>
       private void InitializeComponent()
           this.crystalReportViewer1 = new 
           // crystalReportViewer1
           this.crystalReportViewer1.ActiveViewIndex = -1;
           this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
           this.crystalReportViewer1.Location = new System.Drawing.Point(0, 0);
           this.crystalReportViewer1.Name = "crystalReportViewer1";
           this.crystalReportViewer1.ReportSource = 
                "C:\\Crystal Report\\CrystalReport2.rpt";
           this.crystalReportViewer1.Size = new System.Drawing.Size(576, 349);
           this.crystalReportViewer1.TabIndex = 0;
           // Form1
           this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
           this.ClientSize = new System.Drawing.Size(576, 349);
           this.Name = "Form1";
           this.Text = "Form1";


       /// <summary>
       /// The main entry point for the application.
       /// </summary>
       static void Main() 
           Application.Run(new Form1());


You can modify the report and these sections:

  • Report Header
  • Page Header
  • Details
  • Report Footer
  • Page Footer

Change colors, font, date, style, add more charts…..etc. using the Report tab next to the Windows Form tab.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Ahmed jamil Kattan
Web Developer
United Kingdom United Kingdom
Ahmed J. Kattan Bachelor degree from Jordan University of Science and Technology computer science department, Master Degree from University of Essex and PhD student at University of Essex ”United Kingdom”, I have written several applications, designed multiple algorithms and several publications. My favorite languages are C++ and C#.

see to view Ahmed Kattan's online CV.

You may also be interested in...


Comments and Discussions

QuestionI'm facing the problem of asking user and password. Pin
Leo Rajendra Dhakal15-May-17 18:07
groupLeo Rajendra Dhakal15-May-17 18:07 
Questionsolution Pin
nayeemnayeem28-May-13 20:34
membernayeemnayeem28-May-13 20:34 
Questioncrystal report Pin
cpkranga25-Apr-12 1:00
membercpkranga25-Apr-12 1:00 
Questionwhat is user &password Pin
leo_messi1927-Aug-07 5:44
memberleo_messi1927-Aug-07 5:44 
GeneralCrystal Reports is garbage Pin
fdsafasdfaf7-Jun-07 10:27
memberfdsafasdfaf7-Jun-07 10:27 
GeneralCrystal report chart problem Pin
Member #288043428-Mar-07 9:59
memberMember #288043428-Mar-07 9:59 
GeneralRe: Crystal report chart problem Pin
Ahmed jamil Kattan28-Mar-07 10:37
memberAhmed jamil Kattan28-Mar-07 10:37 
GeneralRe: Crystal report chart problem Pin
Hanna Y29-Mar-07 4:27
memberHanna Y29-Mar-07 4:27 
GeneralRe: Crystal report chart problem Pin
Shazia101013-Jul-07 2:17
memberShazia101013-Jul-07 2:17 
Generalusing stored procedure Pin
Member #38243136-Mar-07 0:12
memberMember #38243136-Mar-07 0:12 
GeneralRe: using stored procedure Pin
Ahmed jamil Kattan12-Mar-07 17:58
memberAhmed jamil Kattan12-Mar-07 17:58 
Generalu r awesome Pin
Saadz17-Dec-06 8:42
memberSaadz17-Dec-06 8:42 
QuestionCrystal Reports Pin
fao426-Nov-06 20:23
memberfao426-Nov-06 20:23 
QuestionHow to re-set the page footer and header? Pin
adeles8-Jun-06 20:52
memberadeles8-Jun-06 20:52 
GeneralProblem with report Pin
countercheck7-Feb-06 2:36
membercountercheck7-Feb-06 2:36 
Questiondatabase login window popup Pin
dinoniko27-Nov-05 11:32
memberdinoniko27-Nov-05 11:32 
AnswerRe: database login window popup Pin
Ahmed jamil Kattan29-Nov-05 5:07
memberAhmed jamil Kattan29-Nov-05 5:07 
QuestionNo user name or password Pin
dinoniko29-Nov-05 11:44
memberdinoniko29-Nov-05 11:44 
AnswerRe: No user name or password Pin
Ahmed jamil Kattan29-Nov-05 15:00
memberAhmed jamil Kattan29-Nov-05 15:00 
QuestionRe: No user name or password Pin
dinoniko30-Nov-05 10:15
memberdinoniko30-Nov-05 10:15 
AnswerRe: database login window popup Pin
bolzmaster30-Nov-05 0:58
memberbolzmaster30-Nov-05 0:58 
AnswerRe: database login window popup Pin
Noble D. Bell5-Jan-06 16:38
memberNoble D. Bell5-Jan-06 16:38 
GeneralRe: database login window popup Pin
Hans van den Bovenkamp14-Aug-06 8:45
memberHans van den Bovenkamp14-Aug-06 8:45 
GeneralRe: database login window popup Pin
Lahoo18-May-07 6:10
memberLahoo18-May-07 6:10 
QuestionCrystal Report Problem Pin
Muhammad Waqas Butt22-Sep-05 23:09
memberMuhammad Waqas Butt22-Sep-05 23:09 
AnswerRe: Crystal Report Problem Pin
kashifjaat22-Nov-12 18:06
memberkashifjaat22-Nov-12 18:06 
GeneralProblem when loading ReportDocument Pin
agmb28-Jun-05 3:34
memberagmb28-Jun-05 3:34 
GeneralRe: Problem when loading ReportDocument Pin
Ahmed jamil Kattan28-Jun-05 20:56
memberAhmed jamil Kattan28-Jun-05 20:56 
GeneralCrystal Reports from XML Pin
unitecsoft10-Jun-05 12:38
memberunitecsoft10-Jun-05 12:38 
GeneralRe: Crystal Reports from XML Pin
Ahmed jamil Kattan10-Jun-05 21:13
memberAhmed jamil Kattan10-Jun-05 21:13 
GeneralThanks !!! Pin
Trance Junkie2-Jun-05 21:43
memberTrance Junkie2-Jun-05 21:43 
GeneralRe: Thanks !!! Pin
Ahmed jamil Kattan3-Jun-05 21:00
memberAhmed jamil Kattan3-Jun-05 21:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170813.1 | Last Updated 3 Jun 2005
Article Copyright 2005 by Ahmed jamil Kattan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid