take web application ,then go to add new item and take crysatlreport1.rpt file
on default.aspx page take button
and add refrence of these two namespace
using
CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
and do the following code->
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 CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlDataReader dr;
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
}
public DataTable getdata()
{
con.Open();
SqlCommand cmd = new SqlCommand("sp_select", con);
// cmd.Parameters.AddWithValue("@name", TextBox1.Text); For parameterized report
cmd.CommandType = CommandType.StoredProcedure;
dr= cmd.ExecuteReader();
dt.Load(dr);
return dt;
}protected void Button1_Click(object sender, EventArgs e)
{
dt = getdata();
ReportDocument doc = new ReportDocument();
doc.Load(Server.MapPath("CrystalReport1.rpt"));
doc.SetDataSource(dt);
// doc.SetParameterValue("@name", TextBox1.Text); For parameterized report
CrystalReportViewer1.ReportSource = doc;
CrystalReportViewer1.RefreshReport();
}
}
}
output will come like this
on default.aspx page take button
and add refrence of these two namespace
using
CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
and do the following code->
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 CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlDataReader dr;
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
}
public DataTable getdata()
{
con.Open();
SqlCommand cmd = new SqlCommand("sp_select", con);
// cmd.Parameters.AddWithValue("@name", TextBox1.Text); For parameterized report
cmd.CommandType = CommandType.StoredProcedure;
dr= cmd.ExecuteReader();
dt.Load(dr);
return dt;
}protected void Button1_Click(object sender, EventArgs e)
{
dt = getdata();
ReportDocument doc = new ReportDocument();
doc.Load(Server.MapPath("CrystalReport1.rpt"));
doc.SetDataSource(dt);
// doc.SetParameterValue("@name", TextBox1.Text); For parameterized report
CrystalReportViewer1.ReportSource = doc;
CrystalReportViewer1.RefreshReport();
}
}
}
output will come like this

No comments:
Post a Comment