Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No valid report source is available- crystal reports

I have created a report using crystal reports. I am using visual studio 2010. The problem occurs when I try to go to another page. When I try to navigate to page 2 or last page the error No valid report source is available appears on the screen. Does anyone have any idea what I need to do? Thanks for your time

like image 409
mikespiteri Avatar asked Sep 13 '11 08:09

mikespiteri


People also ask

Why is my crystal report blank?

A report might be blank or missing data if the wrong fields are being used, the wrong criteria is in the Select Expert, or the table joins are not set to Left Outer Join.

Is Crystal Reports still relevant?

The Standard and Professional editions were discontinued with the release of SAP Crystal Reports 2008. SAP Crystal Reports Xi Developer edition remains available and does everything that Standard and Pro could do - and more.


1 Answers

Store you report in Session and then give report source from session on page post back

protected void Page_Load(object sender, EventArgs e)
{
       if (IsPostBack)
        {
            try
            {
                CrystalReportViewer1.ReportSource = (ReportDocument)Session["Report"];
                CrystalReportViewer1.RefreshReport();
                CrystalReportViewer1.DataBind();
            }
            catch (Exception ex)
            {

               // throw;
            } 
        }

    }
    protected void CrystalReportViewer1_PreRender(object sender, EventArgs e)
    {

    }
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        ReportDocument rptDoc = new ReportDocument();
        rptDoc.Load(Server.MapPath("Reports\\BalanceReportNew\\BalanceReport.rpt"));
        rptDoc.SetDataSource(ReportData());
        Session["Report"] = rptDoc;
        CrystalReportViewer1.ReportSource = rptDoc;
        CrystalReportViewer1.RefreshReport();
        CrystalReportViewer1.DataBind();
    }
    public DataTable ReportData()
    {
        string ClassName = ddlClass.SelectedValue;
        string Division = ddlDivison.SelectedValue;
        string Subject = ddlSubjects.SelectedValue;
        DataTable ReportData = objRpt.getReportData(ClassName, Division, Subject);
        return ReportData;
    }
like image 50
Khalid Rafique Avatar answered Oct 13 '22 00:10

Khalid Rafique