DotnetPrograming

Dotnet Programing : Dotnet Interview Questions,CrystalReports-Datagrid-DotnetRemoting-DropDownList-LINQ-ListView-N-Tier Architecture-Serialization-smartClinetApplications-UserControls-ValidationControls-WebServices.

Archive for the ‘Cryastal Reports’ Category

.NET Crystal Reports from multiple tables

Posted by dotnetprograming on April 23, 2009

All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb) . Please take a look at the database structure before you start this tutorial – Click here to see Database Structure .

Here we are going to do is to generate Crystal Reports from multiple tables. Here we have three table (ordermaster , orderdetails amd product ) and we are generating report from these three tables by connecting each tables with their related fields.

Open Visual Studio .NET and select a new Visual Basic .NET Project.
From main menu in Visual Studio select PROJECT–>Add New Item . Then Add New Item dialogue will appear and select Crystal Reports from the dialogue box.
Select Report type from Crystal Reports gallery.
Accept the default settings and click OK.

Next step is to select the appropriate connection to your database. Here we are going to select OLEDB connection for SQL Server

Select OLE DB (ADO) from Create New Connection .
Select Microsoft OLE DB Provider for SQL Server .
Next screen is the SQL Server authentication screen . Select your Sql Server name , enter userid , password and select your Database Name . Click next , Then the screen shows OLE DB Property values , leave it as it is , and click finish.

Then you will get your Server name under OLEDB Connection from there select database name (Crystaldb) and click the tables , then you can see all your tables from your database.

Select all table from the table list to right side list box, because we are creating report from three tables ( OrderMaster, OrderDetails, Product) .
The next step is to make relation between these selected tables. Here we are connecting the related fields from each table. For that we arrange the tables in visible area in the list (this is not necessary ) and select the field we are going to make relation and drag to the related field of the other table. After made the relation the screen is look like the following picture .
Next step is to select the fields from the tables . Here we are selecting only Customername , orderdate from ordermastertable , Productname from product table and quantity from order details.

Click the Finish button because now we are not using other functionalities of this wizard. After that you will get the Crystal Reports designer window . You can arrange the fields in the designer window according to your requirement to view the report . For rearranging you can drag the field object in the screen . For editing right click the field object and select Edit Text Object. The following picture shows the sample of designer window after rearrange the field.

Now the designing part is over and the next step is to call the created Crystal Reports in VB.NET through Crystal Reports Viewer control .

Select the default form (Form1.vb) you created in VB.NET and drag a button and CrystalReportViewer control to your form.

Select Form’s source code view and put the code on top

Imports CrystalDecisions.CrystalReports.Engine

Put the following source code in the button click event

VB.NET Source Code

Imports CrystalDecisions.CrystalReports.Engine
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim cryRpt As New ReportDocument
cryRpt.Load(“PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt”)
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
End Sub
End Class

NOTES:

cryRpt.Load(“PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt”)

The Crystal Report is in your project location, there you can see CrystalReport1.rpt . So give the full path name of report here.

After you run the source code you will get the report like this.

Here we connected three tables related field and get the result . If you have any comments please contact the email address in our contact page.

Posted in Cryastal Reports | Leave a Comment »

.NET Crystal Reports for Beginners

Posted by dotnetprograming on April 23, 2009

Start your first VB.NET Crystal Reports .

All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb) . Please take a look at the database structure before you start this tutorial – Click here to see  Database Structure.

Open Visual Studio .NET and select a new Visual Basic .NET Project.

Create a new Crystal Reports for Product table from the above database crystalDB. The Product Table has three fields (Product_id,Product_name,Product_price) and we are showing the whole table data in the Crystal Reports.

From main menu in Visual Studio select PROJECT–>Add New Item . Then Add New Item dialogue will appear and select Crystal Reports from the dialogue box.

Select Report type from Crystal Reports gallery.

Accept the default settings and click OK.

Next step is to select the appropriate connection to your database. Here we are going to select OLEDB connection for SQL Server

Select OLE DB (ADO) from Create New Connection .

Select Microsoft OLE DB Provider for SQL Server .

Next screen is the SQL Server authentication screen . Select your Sql Server name , enter userid , password and select your Database Name . Click next , Then the screen shows OLE DB Property values , leave it as it is , and click finish.

Then you will get your Server name under OLEDB Connection from there select database name (Crystaldb) and click the tables , then you can see all your tables from your database.

From the tables list select Product table to the right side list .

Click Next Button

Select all fields from Product table to the right side list .

Click Finish Button. Then you can see the Crystal Reports designer window . You can arrange the design according your requirements. Your screen look like the following picture.



Select Form’s source code view and put the code on top


Imports CrystalDecisions.CrystalReports.Engine


Put the following source code in the button click event


VB.NET Source Code

Imports CrystalDecisions.CrystalReports.Engine
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim cryRpt As New ReportDocument
cryRpt.Load(“PUT CRYSTAL REPORT PATH E\CrystalReport1.rpt”)
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
End Sub
End Class


NOTES:


cryRpt.Load(“PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt”)


The Crystal Reports is in your project location, there you can see CrystalReport1.rpt . So give the full path name of report here.


After you run the source code you will get the report like this.

Posted in Cryastal Reports | Leave a Comment »

What is Crystal Report

Posted by dotnetprograming on April 23, 2009

Crystal Report is a Reporting application that can generate reports from various Data Sources . We can Create Reports , Print and Print Preview of reports from Crystal Reports . Crystal Reports are compatible with most popular development environments like VB.NET etc. and SQL Server also . In the following sections you can find useful resources for generating reports from VB.NET with Crystal Report .

Posted in Cryastal Reports | Tagged: | Leave a Comment »