aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Crystal Reports Example in using Dataset or Datatable

Dec 2, 2014

Here I will explain how to create crystal reports in using dataset or datatable with example in c#, in visual studio 2010 or crystal reports example in with dataset or datatable. Crystal Report is standard reporting tool for visual studio by using these we can display reports regarding user information and charts related to user activities etc and crystal reports need minimal coding to display result.


In Previous posts I explained
how to install crystal reports in visual studio 2010 and how to create rdlc reports using, create crystal reports with using oledb connection in, Pass parameters to crystal reports in, pass parameters to rdlc reports using and many articles related to crystal reports,, c#, . Now I will explain how to create crystal reports in using dataset or datatable with example in c#, in visual studio 2010.  

Before start implementation first design new table in your database and give name UserInfomation

Int(set identity property=true)

After completion of table creation enter some dummy data because we need to use that data to populate reports.

Now Open visual studio and create new website after that right click on your website and select Add New item à in that select Dataset and give proper name and click Add like as shown below

Now Open Dataset and add new datatable for that right click Add à Select Datatable like as shown below

Once we add datatable next step is we need to add columns for that right click on datatable select Add à select Column like as shown below

Here you need to remember one point that is the entire column names should be same as the table (UserInfomation) which we created in database

Suppose if you want to change datatype for any column select respective column right click and select properties

Now Change datatype for that respective column lilke as shown below

Once we completed adding datatable to dataset now right click on your website and select Add New item à in that select Crystal Report and click Add

After add crystal report it will prompt Crystal Report Gallery window in that select using the Report wizard option and click OK

Once we add Report Wizard it will open another window Standard Report Creation Wizard to select database connection for crystal report. Here we will select previously created UserInformation table from respective database like as shown below

Once we select our dataset and tables press Next button now it will ask you to select required columns to display in crystal report from dataset based on your requirement like select all columns or only few columns and click Next button like as show below

Now in next windows it will give you option to group columns or Record Selection or other options but all are optional so you can click Next à Next àFinish Once we finished everything it will create crystal report like as shown below

Now open your Default.aspx page and drag and drop CrystalReportViewer control from Reporting tab.

If you check your Default.aspx page code that will be like as shown below

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
<title>Crystal Reports Example in with dataset or datatable</title>
<form id="form1" runat="server">
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
Now open your code behind file write the code like as shown below

C# Code

using System;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;

public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
ReportDocument reportdocument = new ReportDocument();
UserInformation dsCustomers = new UserInformation();
using (SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB"))
SqlCommand cmd = new SqlCommand("select * from userinformation", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

CrystalReportViewer1.ReportSource = reportdocument;


Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim reportdocument As New ReportDocument()
Dim dsCustomers As New UserInformation()
Using con As New SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB")
Dim cmd As New SqlCommand("select * from userinformation", con)
Dim da As New SqlDataAdapter(cmd)
da.Fill(dsCustomers, "UserInfo")
End Using
CrystalReportViewer1.ReportSource = reportdocument
End If
End Sub
End Class

Now run your application your report will be like this


create Crystal Reports Example in using Dataset or Datatable

Download Sample Code Attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Abdul Khaliq said...

Nice Article..........

Bachu Ramu said...

how to create a parameter in crystal report

Bhavesh Patel said...

Nice....Good Post.

Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.