In my previous article, I described how to create Crystal Report with Oracle Views.
In this article, I am going to demonstrate how to create a Crystal Report with ADO.NET
You will find this article very interesting, simple and easy to understand.
This article needs basic knowledge of .NET.
Note: Please vote for this article.
No background knowledge is needed for this article. This article is very simple and just requires very basic knowledge of .NET.
But I recommend reading my previous article as well, though it has no direct relation with this article.
Using the Code
Now enough of theory, we will move to our point.
So here we go... I have created 2 sample tables for this project. Scripts of tables are
as follows, with some sample insert query to have sample data.
create table tbl_project
create table tbl_project_group
insert into tbl_project values(1,'CrystalReportWithOracle',1);
insert into tbl_project values(2,'Ajax Application',2);
insert into tbl_project_group values(1,'windows application');
insert into tbl_project_group values(2,'Web application');
First of all, create a project in Microsoft Visual Studio 2005 and name it
Then create a form as
frmMain and add a Crystal report viewer control to this form.
Add a Reference to
Step 1: Adding A DataSet and DataTable
DataSet to your Project and name it as
myDataSet, as follows:
Now add a
Now add columns to your
DataTable as given below in the image.
Your column name and
datatype should be the same as that in your database.
datatype of the
DataTable columns as shown below:
Now save this
Now we have created our
DataTable. The next step is to create a
Step 2: Adding A Crystal Report
Add a Crystal report to the project and name it as
Choose Using the report wizard.
Choose the data source from project data which is
my_dataset in our case.
Choose the columns to be displayed on the report.
Add a group by column, if you want.
Now our designing part is complete.
Step 3: Binding Our Report to our DataSource
Below is the C# code to bind our report to the
public partial class frmMain : Form
private void frmMain_Load(object sender, EventArgs e)
objRpt = new my_rpt();
String ConnStr = "SERVER=mydb;USER ID=user1;PWD=user1";
OracleConnection myConnection = new OracleConnection(ConnStr);
String Query1 = "select a.PROJECT_ID,a.PROJECT_NAME,b.GROUP_NAME from
tbl_project a,tbl_project_group b where a.group_code= b.group_code";
OracleDataAdapter adapter = new OracleDataAdapter(Query1, ConnStr);
DataSet Ds = new DataSet();
if (Ds.Tables.Rows.Count == 0)
MessageBox.Show("No data Found", "CrystalReportWithOracle");
root = (CrystalDecisions.CrystalReports.Engine.TextObject)
root.Text = "Sample Report By Using Data Table!!";
crystalReportViewer1.ReportSource = objRpt;
Points of Interest
My other articles of interest are:
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.