Here I will display an Employee report. The user can see any employee report by typing his/her name.
Now we will learn this step-by-step.
The following is my SQL Server table, for which I will show a Crystal Report.
Image 1.
Open Visual Studio and select File -> New Web Site.
Image 2.
Right-click on the project in Solution Explorer then select Add New Item then select DataSet.
Image 3.
Now Right-click and seelct Add -> Data Table.
Image 4.
Now right-click on the Header and select Add -> Column.
Be sure the column name and their Data type are the same as in your data table. You can change the data type by selecting your added column. Then right-click on something and select the Data type property.
Image 5.
Now right-click on the project in Solution Explorer then select Add New Item then select Crystal Report.
Image 6.
Image 7.
Select Project Data -> ADO.NET Data Sets then select your new Data Set then select your table then click Next.
Image 8.
Now select the columns for the report and click on Finish.
Image 9.
Now on your aspx page add a text box, button and a report viewer as in the following:
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="EmployeeReport.aspx.cs" Inherits="EmployeeReport" %>
- <%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
- Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Employee Report</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <table cellpadding="10" cellspacing="10" width="70%" height="300px" align="center"
- style="border: solid 2px gray;">
- <tr>
- <td align="center" style="background-color: SkyBlue;">
- Employee Name:#
- <asp:TextBox ID="txtEmployeeName" runat="server"></asp:TextBox>
- <asp:Button ID="btnShowReport" runat="server" Text="Show Report" OnClick="btnShowReport_Click" />
- </td>
- </tr>
- <tr>
- <td align="center">
- <asp:Panel ID="pnlReport" runat="server" Height="400px">
- <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
- </asp:Panel>
- </td>
- </tr>
- </table>
- </div>
- </form>
- </body>
- </html>
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using System.Data;
- using System.Data.SqlClient;
- using CrystalDecisions.CrystalReports.Engine;
- public partial class EmployeeReport : System.Web.UI.Page
- {
- SqlConnection con;
- SqlDataAdapter da = new SqlDataAdapter();
- DataSet ds = new DataSet();
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void btnShowReport_Click(object sender, EventArgs e)
- {
- con = new SqlConnection(@"Data Source=MyPC\SqlServer2k8;Integrated Security=True;Initial Catalog=Test");
- da = new SqlDataAdapter("select * from Employee where EmployeeName like '%" + txtEmployeeName.Text + "%' ", con);
- da.Fill(ds);
- ReportDocument rd = new ReportDocument();
- rd.Load(Server.MapPath("ShowEmployeeReport.rpt"));
- rd.SetDataSource(ds.Tables[0]);
- CrystalReportViewer1.ReportSource = rd;
- }
- }

Image 10.

Image 11.

Rahul Kumar SaxenaPosted Apr 1, 2016, 5:20 AM
Thanks Sonu Chaudhary
Rahul Kumar SaxenaPosted Apr 1, 2016, 5:20 AM
Thanks Nikunj
Sonu ChaudharyPosted Mar 31, 2016, 12:03 PM
good one article
Nikunj TrivediPosted Aug 13, 2015, 7:52 AM
Thank u sir, Its a very useful blog for crystal report. But here i face one problem after viewing data in crystal report viewer. When I press PRINT button then Printer List not available. No one printer display to select to print. Please Help me to solve this.
Rahul Kumar SaxenaPosted May 18, 2015, 12:03 AM
Thanks Muhammad Abdul Manan
Rahul Kumar SaxenaPosted May 18, 2015, 12:02 AM
Thanks Gorki Lituma Guerrero
Muhammad Abdul MananPosted May 17, 2015, 4:45 PM
niceee Article Rahul
Gorki Lituma GuerreroPosted May 7, 2015, 12:54 PM
Excelente, me sirvi?, gracias...
Rahul Kumar SaxenaPosted Apr 13, 2015, 2:44 PM
Thanks Santhakumar Munuswamy...
Santhakumar MunuswamyPosted Apr 13, 2015, 2:36 PM
Thanks for sharing
Santhakumar MunuswamyPosted Apr 13, 2015, 2:36 PM
Good work..
Rahul Kumar SaxenaPosted Feb 26, 2015, 4:37 AM
Thanks ...
Rahul Kumar SaxenaPosted Feb 24, 2015, 8:09 AM
Thanks Md. Raskinur Rashid..
Md. Raskinur RashidPosted Jan 22, 2015, 7:01 AM
Thanks. very useful...