Crystal Reports for Visual Studio 2013 – ASP.NET ( Web Form ) + CrystalReportViewer
Create DataSet Item under Web Application Project. Add TableAdapter on DataSet. Select ADO.NET DataSet on Crystal Reports & Design Report Layout. |
Default.aspx |
<CR:CrystalReportViewer ID="SoccerReportViewer" runat="server" AutoDataBind="true" /> |
Default.aspx.cs |
using CrystalDecisions.CrystalReports.Engine; using System.Data; using System.Data.SqlClient; protected void Page_Init(object sender, EventArgs e) { ReportDocument rd; if (!Page.IsPostBack) { rd = new ReportDocument(); rd.Load(Server.MapPath(@"~\Report.rpt")); rd.SetDataSource(this.getDataTable()); Session["ReportDocument"] = rd; } else { rd = (ReportDocument)Session["ReportDocument"]; } this.SoccerReportViewer.ReportSource = rd; } protected void Page_Load(object sender, EventArgs e) { } private DataTable getDataTable() { String connectionString = "Data Source=VMSER001;Initial Catalog=Soccer;Persist Security Info=True;User ID=sa;Password=xxxxxx"; SqlConnection con = new SqlConnection(connectionString); con.Open(); String SqlString = "SELECT * FROM PLAYER_VIEW"; SqlCommand cmd = new SqlCommand(SqlString, con); SqlDataReader dr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); return dt; } |