Click here to Skip to main content
12,449,911 members (41,269 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked

Crystal Reports using C#.NET 2003 Windows Application

, 25 Jul 2006
Rate this:
Please Sign up or sign in to vote.
Crystal Reports for using C#.NET 2003 Windows Application (From Scratch to Deployment)

Step 1 :-

To open the crystal report document, Right Click on your project.

Select Add -> Add New Item. New window will appear as below. Give Name to your report.


 Sample screenshot






























Step 2:-

After clicking Open u will see another window giving you options how do you want to create the report, using Report Expert or from Blank Report or from an existing report. Here I am selecting second option i.e. As a Blank Report.

Now your Crystal Report Document will get opened. On the left hand side there you will see  Field Explorer from where you can interact with database.

(If Field Explorer is not there then to open it you can use shortcut key Ctrl + Alt + T)


Step 3:-

Now to select database, (My Database is stored in SQL Server 2000)

Right Click on Database Fields in Field Explorer.

Select Add/Remove Database -> OLEDB(ADO) ->Make New Connection -> Microsoft OLE DB Provider for SQL Server (As I am using SQL Server 2000). Click on Next  and  give your connection Information, Click on Next and then Click on Finish.


Now you can add your table/s, view/s which you required for the Report. The window looks like this.


Sample screenshot 




























Step 4: -

 Now in your Field Explorer you can see your chosen Table/View. Drag the Fields you want to show in the report in Details Section. The screen will appear as follows.



Sample screenshot 




























The fields in Details section are Field Objects and the fields in Page Header, Report Header are Text Objects.



Step 5:-

Now to show this report, Take a form & add a CrystalReportViewer to it.(Just drag CrystalReportViewer  from  Tool box on the form).


For crystal reports add name spaces are important


using CrystalDecisions.Shared;

using CrystalDecisions.CrystalReports.Engine;


(Here I am showing report on Page Load, same code can be written on Button Click if wanted.)


Now even if we have connected database to report but if we changed database then it is not feasible to create new crystal reports again & again so we can use TableLogOnInfo to connect report to Database programmatically.

Create Object of that as

private TableLogOnInfo LogInfo = new TableLogOnInfo();


The function can be written as


    private void SetLogonInfo()









       catch(Exception ex)








Now we need to create  object of the report. There are various ways to show report.


a)      Create one object of Report Document that can be use to every report which are going to be shown on that CrystalreportViewer can be created as

            ReportDocument O_Report=new ReportDocument();

    We can use this object to every report and need to give path while loading the



b)    Create different objects for different reports as


     rptShowList O_showList = new rptShowList();


(Here I am using second option).


Make DataBase Connection as



Step 6:-

        Now I want to show AddressList of the users whose number is greater than 15. For that I will fill DataTable with these records and then attach it to the report.


DataTable DT = new DataTable();



              string CmdStr="";

              CmdStr = “Select * from Vw_AddressList where User_Number>15”;


              SqlDataAdapter Adpt=new SqlDataAdapter(CmdStr,Connection);




           catch(Exception ex)










Step 7:-

    Now set the above filled DataTable as Reports dataSource.




Step 8: -

    Set the report as crystal report viewer report source to bind report to viewer. 

CryStalReportViewer1.ReportSource = O_Report1111;



How to Change the properties of Fields on report programmatically.


 The Fields on the Detail section,Formula Fields,group Name Fields are the FieldObjects. We can change it’s properties like font,size programmatically.

Get the name from the properties window & create object of that field.get the section number & change it’s properties.


e.g. In the above Report User Number and user Streetasddress are the field objects. We can change there properties as


FieldObject fUserNumber = FieldObject)o_showlist.Sections3.ReportObjects["Field1"];


fFullName1.ApplyFont(new Font(Arial,8.25F));


Same can be done with Text Object.



We can change properties of Formula Field in different way also.

O_showlist.DataDefinition.FormulaFields["Header"].Text = “Address List”;



Formula Fields:-


  Here I will just give sample of how to use formula field. It’s out of scope to give whole Formula Field Description.


In my database I have stored Gender field as “M” or “F” but in report I want to show it as “Male”, “Female” etc.


·         Right Click on Formula Field -> New

·         Give Formula Name.

The Formula Editor screen will appear as follows-

Sample screenshot 





























The left side Section contains database fields there we can select on which field we want to write formula. Middle section is Functions. We can apply different types of functions to formula. The Right section is of Operators where we use operators in formula.


Now I have written code as –


if({Vw_AddressList.Gender})= 'M' then










Deploying the Crystal Report Dot Net Application:


Step 1:- Right click on Solution -> Add New Project

Sample screenshot 





























Select SetUp and Deployment Projects -> Setup Project.

Give name to your Setup.


Step 2:- To add Exe and other files-


    In File System, Right click on Appllication Folder (It creates folder at Win/Sys path generally) -> Add -> Project Output -> select  Primary output & other needed files.

    Up to this is general Deployment process. If your application includes Crystal Reports you need to do some extra.


a)    Adding Merge Module:-

·         Right Click on Setup project -> Add -> Merge Module

·         Select ‘Crystal_regwiz2003.msm’, Crystal_Managed2003.msm,           Crystal_Database_Access2003_enu.msm, Crystal_Managed2003.msm

·         Click on Open.


b)      Now important thing is that When you run this Set up on another sytem it will give you error  of “Keycode32.Dll”

The error is due to not giving Registration key to Merge Module File       ‘Crystal_regwiz2003.msm’ To do that Right Click on  ‘Crystal_regwiz2003.msm’ and select Properties.

    In properties select ‘(MergeModuleProperties)’ ->

 Enter your key at ‘License Key‘.

Now the License key can be your Crystal Report product key or you can get it from,

Help(Menu of dot net) -> About Microsoft Development Environment.

There you will see the string “Crystal Reports for Visual Studio .NET AAP50-GS00000-U7000RN“(can be different for different versions).Your key is 'AAP50-GS00000-U7000RN'.


Now build the solution & your set up is ready.


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

Hrushikesh Mokashi
Web Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

Questioncrustal reports Pin
panduRajju5-Apr-12 18:53
memberpanduRajju5-Apr-12 18:53 
GeneralFormula Fields Pin
longhn5-Nov-08 22:47
memberlonghn5-Nov-08 22:47 
Questionhow change font at runtime Pin
kianoosh soorani3-Nov-07 4:07
memberkianoosh soorani3-Nov-07 4:07 
Generalformulae fields Pin
suparichit3-Sep-07 1:22
membersuparichit3-Sep-07 1:22 
GeneralRe: formulae fields Pin
Hrushikesh Mokashi20-Sep-07 21:38
memberHrushikesh Mokashi20-Sep-07 21:38 
GeneralCrystal Reports Problem Pin
khuhro31-Aug-07 5:53
memberkhuhro31-Aug-07 5:53 
How to handle this Problem
1. when I add report than I give servername but when iam deployment application and istall another machine change server name create problem not run report how I can solve this,

GeneralRe: Crystal Reports Problem Pin
Hrushikesh Mokashi20-Sep-07 21:40
memberHrushikesh Mokashi20-Sep-07 21:40 
GeneralRe: Crystal Reports Problem Pin
gaurav.ipec29-Jul-10 0:49
membergaurav.ipec29-Jul-10 0:49 
QuestionCombine a Database field in a text object programmatically ? Pin
ledz25-Jul-07 2:43
memberledz25-Jul-07 2:43 
Generalthanks Pin
nadeem111as11-Jun-07 6:21
membernadeem111as11-Jun-07 6:21 
Questioncan anybody send dynamic crystal report in windows Pin
madhuoo30-Mar-07 23:30
membermadhuoo30-Mar-07 23:30 
QuestionProgressBar while loading Report Pin
sDisco1-Mar-07 1:32
membersDisco1-Mar-07 1:32 
GeneralChanging database type at run time Pin
AlexEvans28-Nov-06 16:07
memberAlexEvans28-Nov-06 16:07 
GeneralAssigning the dataset only works for one table Pin
Jan Schreuder2-Aug-06 2:47
memberJan Schreuder2-Aug-06 2:47 
Questionhow to view the contents in crystal reports using dataset generated at run time Pin
puneetaggarwal1629-Jul-06 22:06
memberpuneetaggarwal1629-Jul-06 22:06 
GeneralRe: how to view the contents in crystal reports using dataset generated at run time [modified] Pin
Jan Schreuder1-Aug-06 10:50
memberJan Schreuder1-Aug-06 10:50 
GeneralRe: how to view the contents in crystal reports using dataset generated at run time Pin
Jan Schreuder2-Aug-06 2:43
memberJan Schreuder2-Aug-06 2:43 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 26 Jul 2006
Article Copyright 2006 by Hrushikesh Mokashi
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid