Professional Documents
Culture Documents
CRYSTEL10
CRYSTEL10
Introduction
This article gives an idea as how to use Crystal report in .Net Windows Application with parametrized
queries and Oracle as Database using dataset.I had searched on internet for articles related to Crystal
Report with parametrized query with Oracle,but I was unable to find any good article on this topic.So I
am posting my article on this topic.
There are three main points in this article.
1. Crystal Report with parametrized query.
2. Using Oracle Views because here stored procedure will not be able to do this job because of the fact
that Oracle Stored Procedure does not return Multiple Rows(Record Set) as Sql Server Stored
Procedures do.
3. Using DataSet.
Hence I have used Oracle views in this project to bind the Crystal Report and Dataset.Then I wrote my
parametrized query on the view as we do generally on database tables. So this Project will give a good
idea on how to Use Crystal Report with Oracle. There are many methods to do this job, even we can
create Oracle packeges which will return mutiple records as SQl Server Stored Procedures. But I found
this way simple and fast to do.
Background
No special background knowledge is needed for this article. Any beginner or Intermediate will be able to
understand this code.It will be good if you have a basic knowledge of database views.
Using the code
I have created 2 sample tables and a view for this project. Scripts of tables and view are as follows, with
some sample insert query to have sample data
PROJECT_ID NUMBER(4),
PROJECT_NAME VARCHAR2(150),
GROUP_CODE NUMBER(2)
GROUP_CODE NUMBER(2),
GROUP_NAME VARCHAR2(100)
);
a.GROUP_CODE "GROUP_CODE"
a.GROUP_CODE=b.GROUP_CODE;
Step 1:
First off all create a project in Microsoft Visual Studio 2005 and name it CrystalReportWithOracle. Then
add a crystal report to it as shown below.
Step 2:
Then from the available data sources choose OLEDB(ADO) as below
Then Select the Provider as Oracle Provider for OLEDB as in the image
Then Provide the necessary information for databse login as per your oracle Configurations
Step 3:
Then from the available data source add your view which you have created before to the selected table
Container and add your fields which will be displayed in the report as shown below.
Step 4:
Now add a Empty DataSet to your project.
Then You add a Crystal Report Viewer Control from the tool box to your form.
There is a class file DLApplication.cs for the sake of database connectivity. Here you can change your
connection string as per your Oracle configuration. If You are creating your Own connectivity in the form
itself you can ignore this file.
There is a Combo Box in which the user can select his choice of project type so that the application
generates a dynamic report on the user selection. Code to fill the combo box is as follows.
cmb_type.DataSource = dv;
cmb_type.ValueMember = "GROUP_CODE";
cmb_type.DisplayMember = "GROUP_NAME";
cmb_type.SelectedIndex = -1;
In the above code getDataView() function is called with required parameters. This function resides in the
DLApplication class.
The main function which is binding the crystal report is given below, when ever the user changes his
choice from the combo box a new report is generated for the selected combo value.
//
if (Convert.ToInt32(cmb_type.SelectedIndex) == -1 ||
(Convert.ToString(cmb_type.SelectedValue) == "System.Data.DataRowView"))
return;
CrystalReport1 objRpt;
// join query and we will not be able to fill our adapter easily.
adapter.Fill(Ds, "view_project");
if (Ds.Tables[0].Rows.Count == 0)
return;
objRpt.SetDataSource(Ds);
CrystalDecisions.CrystalReports.Engine.TextObject root;
root = (CrystalDecisions.CrystalReports.Engine.TextObject)
objRpt.ReportDefinition.ReportObjects["txtHeader"];
crystalReportViewer1.ReportSource = objRpt;
//
The DLApplication.cs file contains function which returns Oracle Data View, Oracle Data Reader etc. You
can have a look at the class file.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OracleClient;
namespace CrystalReportWithOracle
get
return userId;
set
userId = value;
try
return sqlcon;
try
OracleDataReader objOraDrRead;
objOraCmd.Connection = con;
objOraCmd.CommandType = CommandType.Text;
objOraCmd.CommandText = Sql;
objOraDrRead = objOraCmd.ExecuteReader(CommandBehavior.CloseConnection);
return objOraDrRead;
try
if (thisCon.State != ConnectionState.Closed)
thisCon.Close();
OracleCommand objCmd;
try
objCon.Open();
objCmd = objCon.CreateCommand();
objCmd.CommandText = sQuery;
objCmd.ExecuteNonQuery();
}
catch (Exception ex)
finally
if (objCon.State == ConnectionState.Open)
objCon.Close();
try
OracleDataAdapter oDa;
DataSet ds;
ds = new DataSet();
oDa.Fill(ds);
if (Conn.State != ConnectionState.Closed)
Conn.Close();
return (ds.Tables[0].DefaultView);
finally
if (Conn.State != ConnectionState.Closed)
Conn.Close();
Points of Interest
Oracle Stored procedures do not return multiple records, we can use packege instead,but here I have
used Views which is much more easy and simple to understand.
2. Ajax Techniques.
History
I will update this article to give a more clear picture on this topic
License
This article, along with any associated source code and files, is licensed under The Code Project Open
License (CPOL)
Rehan Ahmad Abbasi I am a Software Engineer having 4 + years of experience in various skill sets.
Proficiency in Asp.net, C#.net, Vb.net, Ado.net, VB 6.0, J2ME, Ajax, Xslt, Xml,
Smart Device (Pocket PC 2003), and Oracle.
Extensive experience with analyzing, designing, development, and maintenance
of Internet, Intranet, Client Server and Object Oriented applications built on .NET
Framework (windows and web app.) and VB 6.0.
Software Developer
(Senior)
Al-Jazirah Corporation
Riyadh KSA
United Arab Emirates
Member
Article Top
Bottom of Form
You must Sign In to use this message board. (secure sign-in)
Top of Form
Bottom of Form
Top of Form
Bottom of Form
Sign In·View Thread·Permalink
hiii
my crystal report is working well but when ever i view the report i have to enter the oracle user
password on run time
i want to avoid it is there is any coading or connection string so that it wont ask on run time????
How can the lines of the report becomecloser? joseccz 11:39 4 May '09
RAAbbasi
Sign In·View Thread·Permalink
Can anyone tell me what issues there are regarding the subject? I've got a CR XI Developer License
which I use to create report files (rpt) and would like to be able to supply these report files to my 3rd
party customers. I was thinking of creating a tool with VS2008 using the Crystal Report Viewer
component. In order to do this, you need to distribute the CR Redistributable Package to enable the
customer to "run" or "refresh" the report.
My question is - do I still need to pay some license or royalties to someone if I want to distribute a
app using the CR Viewer component and the CR Redistributable package?
RAAbbasi
Sign In·View Thread·Permalink
/KB/cs/Crystal_R
Last Visit: 19:00 31 Dec '99 Last Update: 20:39 15 Oct '11
1
oraclequerywithparam.
How to connect oracle server, Pass one or more parameter and execute...
www.geocities.com
ComponentOne ReportViewer for ASP.NET AJAX
Turn any of your Web reports into powerful, printable, Web-ready...
www.componentone.com
See Also...
Step by Step Creation of Crystal Report using its Features Group, Graph, Cross-Tab and Sub Report