27/11/2012

How to prepare a crystal report VB 2010- a tutorial for begginers

Crystal reports need database drivers to connect to connect a data source for accessing data and showing into a report. VB.Net support two methods to access data from data source and publish it .

(i)                  These two methods are The Pull Model: When this model is used to access data from the data source, the data driver directly from data source. This model does not require a dataset means this model does not require the programmer to write any additional code. The crystal report creates and manages the SQL commands for connecting to the data source and retrieving data from it.
Crystal Report-------------Data---------------Data source


(ii)                The Push Method: When this model is used to access the data from data source through creating a dataset.
                                               
Crystal Report---------------Data-------------Dataset-----------Data------------Data source

But, In this post I will only write only about, how to prepare a crystal report by pull method: or manually. When crystal reported created manual, the data added manually to the created report by using various tools from crystal report toolbox and the field explorer window. To create crystal report by pull method or manually follow the following steps
(a)    Right click the project name in solution explorer with and point Add from the shortcut menu. Then click add new Item from Add shortcut menu option

(b)   The add New Items dialog box will open then select Reporting from the list , you will see crystal report in after selecting Reporting heading. Select crystal report and give name blog.rpt

(c)    By default the Crystal report is named as CrystalReport.rpt change the name to blog.rpt and click open report, crystal report gallery  is displayed

(d)   Select  As blank Report by checking the radio button from Crystal report gallery, a new blank crystal report will be open

(e)   You can connect a data source directly and select the fields from database table to be displayed in the crystal. To do so follow the following steps
(a)    Right click of database field in the field explorer windows and then select .

(b)   A list of data sources is displayed select a  Create new connection and dig down  data base files and click of find data base files when you click a pop up will open just select your data base and click open after clicking open you will find all the tables of your database is listed there.

(c)    Just select a tables from the list which you want to use in your crystal report , I have selected CoyEmployee table in my example then click ok now the table is include  database field just dig down your added table and drag those fields which you want to show in your crystal report. The dragged fields should be placed section-3 a heading will be created in section -2 also which will be the subject tag of the report that can be also edited by right clicking on them and editing text object.

(d)   The report Designer displays a various sections of the report such
(i)                  Report Header: The section contains the report title so you can use toolbox and text object and create heading here.
(ii)                Page header: This section contain title of the report, the component you add to this section will be displayed on all the pages of report
(iii)               Details: this section show actual reports
(iv)              Report footer: . The component you add in this section will be show at the end of the page.
Now you have created a report, you can still do lots of things in this crystal report that all cannot be concluded in one post so this Crystal report is ok for trial. Once you have created a crystal report, then how you will show it.
(e)   How you will display a crystal report for that again go to solution explorer and right click on you project then Add then Add window form and open a window form and name it report.vb and click Add.

(f)     Now new window form is open then go to toolbox the drag Crystal report viewer which listed under sub head Reporting and placed it on the window form

(g)    Once you have place it on windows form just select the Crystal Report viewer by clicking on it and go the  property of the report viewer and set the report source as crystal report which you have just created. 


And Now your crystal report viewer is set just press F5 and run the report

No comments:

Post a Comment

What & How