Funding for 'IT Lab' Project, Phase 1: Progress of sticker sales. Purchase a sticker to help us reach our target.Updated: 2010-02-28 11:53
10.7%
Crystal Reports
 

by Eranda Niroshan


Generating reports is a compulsory requirement with the modern software world. Management software, accounting software, controlling software etc... All of them need reporting function to represent the data in convenient manner. For .NET developers’ crystal reports is an essential tool. Crystal Reports is a business intelligence application used to design and generate reports from a wide range of data sources. Crystal Reports has been part of Visual Studio since 1993, and is now the standard for reporting in Visual Studio. Most important thing is crystal reports provide reporting facilities to the form applications as web as web applications.

    Purpose of this article is to provide basics to start building reports to your own application under the visual studio environment. Within this series of articles we are going to talk about huge range of activities related with the crystal reports. Now I’m going to start build a new application with crystal reports.

  •  First of all open visual studio and create a new project under windows form application. 
  •  Open the solution explorer and right click on the project name select Add --> New Item .It will open the Add New Item Window 
  •  Now under categories select Reporting and under template select Crystal Report then give a name to your report and press ok.
  • Now it will open Crystal Reports Gallery Window. Select “as blank report” and press ok.


Now you can see the report is open in a new tab. basically a crystal report has five rows to make easier to the developer, but you’ll not see them in the preview mode. Those five positions are

  • Section 1 ( Report Header)

We can put Header Image or text regarding the Report here

  • Section 2( Page Header)

Header related with particular page goes here

  • Section 3 ( Detail)

This is the most important field. All the repeatable and static data goes to here.

  • Section 4 ( Report Footer)

This is where footer text or something else put regarding the report.

  • Section 5 ( Page Footer)

All others belongs to the page footer goes here.



Likewise you design the applications forms by putting text boxes and buttons you can design the report also. By default there has some tools under toolbox and also you can notice there has a new panel located in the right side that we cannot see in the form designing mode. It is Field Explorer, this is the place you can get data into the report. There has 8 items. Each item is to provide different functionalities. We’ll describe them as its usage.


Insert Data Base table into the Crystal Report

To insert database table we have to use a facility provide under Field Explorer (panel we describe previously). “Database Fields” this item use to get any kind of data from database. It can be a table or result of the SQL query.

  •          Right click on the Database Fields and select database expert, this will open the Database Expert Window

  •         Expand Create New Connection category by clicking top of the “+” symbol

  •         Then expand the sub category named OLE DB (ADO) now it will open the OLE DB (ADO) Window.





   

                

  • Then select SQL Native Client from that window and click next 
  • Now select the SQL server from the Server dropdown and enter your user id and password if you have them otherwise tick the Integrated Security checkbox it will disable the User ID and Password fields
  • Then select your database name from database dropdown.  And click finish.




    Now inserting the database table is finish after that you have to place those data in the report to do so expand the database expert from the Field Explorer panel. Then expand the table name, it contain all the columns which belongs to the particular table. Now simply drag and necessary items (you do not need to drag all the items) into the detail section (Section 3) left to right order. When you drag items into the section 3 you can see it automatically add underlined texts into the section 2 (page Header). That’s the header for the particular Column by default it takes table column name as its header you can modify it by double clicking top on the text.

    So far we create a new Crystal report, insert data into the report. Now go to the form design tab still you can’t see anything in the form. That’s correct that’s not your fault. So far we only develop the report we didn’t include the report into the form window. We need tool called “Crystal Reports Viewer” which comes under reporting category of the tool box. Drag and drop a Crystal Reports Viewer in to the form area. Then select the small arrow in the top right corner and click choose a crystal report link. Select the newly created report from the dropdown list and press ok.

    That’s all you have to do for insert crystal report into your application with database table data. Now save your application and run it.

                   


    Next time we will talk little bit more about Crystal reports. To get more information’s go to the MSDN website and search under Crystal Reports.

    Share/Save
    No votes yet

    Post new comment

    • Web page addresses and e-mail addresses turn into links automatically.
    • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
    • Lines and paragraphs break automatically.

    More information about formatting options