Bind Crystal Reports without Database in ASP.Net using C#

Here, we will learn how to create and bind crystal reports in asp.net without use of any database. we generally use database for bind data to crystal reports, but in this example i will show you how to bind dynamically data to crystal reports at runtime. we will use here dataset method for bind data to crystal reports in asp.net.

First create asp.net web application and right click on Project >> Add New Item >> DataSet

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

- Add new Dataset to asp.net web application for bind dynamically crystal reports.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

- Add New DataTable here for make dynamically columns for data. Add new DataTable in DataSet.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

- After adding new DataTable add some columns which you want to bind in crystal reports. add some columns shows like below screen.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

- do same process for add new columns in DataTable.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

- Here, we took three columns ID, Name, City in this asp.net example.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

- After creating DataTable in Dataset, now create new crystal reports for display data in asp.net.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

- go to Field Explorer >> Database Field >> Database Expert >> Project Data >> ADO.Net DataSets

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

 

- Design the Crystal Reports with columns from Database Filed. drag some columns in crystal reports details section for display crystal reports in asp.net.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

now, add new crystalreportviewer on asp.net web forms for display crystal reports.

write below code for bind data to crystal reports in asp.net.

C# Code

    protected void Page_Load(object sender, EventArgs e)
{
DataSet1 ds = new DataSet1();
DataTable tbll = ds.Tables.Add(“Items”);
tbll.Columns.Add(“id”, Type.GetType(“System.Int32″));
tbll.Columns.Add(“Name”, Type.GetType(“System.String”));

tbll.Columns.Add(“City”, Type.GetType(“System.String”));

DataRow rowss;
int i = 1;
for (i = 1; i <= 9; i++)
{
rowss = tbll.NewRow();
rowss["id"] = i;
rowss["Name"] = “Name” + i;
rowss["City"] = “City” + i;
tbll.Rows.Add(rowss);
}

ReportDocument rept = new ReportDocument();

rept.Load(Server.MapPath(“~/CrystalReport2.rpt”));
rept.SetDataSource((DataTable)ds.Tables[1]);
CrystalReportViewer1.ReportSource = rept;

}

VB.Net Code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim ds As DataSet1 = New DataSet1()
Dim tbll As DataTable = ds.Tables.Add(“Items”)
tbll.Columns.Add(“id”, Type.GetType(“System.Int32″))
tbll.Columns.Add(“Name”, Type.GetType(“System.String”))
tbll.Columns.Add(“City”, Type.GetType(“System.String”))

Dim rowss As DataRow
Dim i As Integer = 1
For i = 1 To 9 Step i + 1
rowss = tbll.NewRow()
rowss(“id”) = i
rowss(“Name”) = “Name” + i.ToString()
rowss(“City”) = “City” + i.ToString()
tbll.Rows.Add(rowss)
Next

Dim rept As ReportDocument = New ReportDocument()
rept.Load(Server.MapPath(“~/CrystalReport2.rpt”))
rept.SetDataSource(CType(ds.Tables(1), DataTable))
CrystalReportViewer1.ReportSource = rept

End Sub

- Here is the out put of dynamically bind data to crystal reports in asp.net using c#.

Create and Bind Crystal Reports without Database in ASP.Net C#

Create and Bind Crystal Reports without Database in ASP.Net C#

Leave a Reply

Your email address will not be published. Required fields are marked *

5 + 7 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">