Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 没有可用的有效报告源-crystal reports_Asp.net_Visual Studio 2010_Crystal Reports - Fatal编程技术网

Asp.net 没有可用的有效报告源-crystal reports

Asp.net 没有可用的有效报告源-crystal reports,asp.net,visual-studio-2010,crystal-reports,Asp.net,Visual Studio 2010,Crystal Reports,我使用crystal reports创建了一个报告。我正在使用VisualStudio2010。当我尝试转到另一页时,问题出现了。当我尝试导航到第2页或最后一页时,屏幕上会出现“无可用的有效报告源”错误。有人知道我需要做什么吗?感谢您抽出时间尝试在此线程中使用解决方案: 根据它所说的,您应该能够通过在代码中提供ConnectionInfo和ReportSource使其工作。将您的报告存储在会话中,然后在返回页面上提供会话中的报告源 protected void Page_Load(object

我使用crystal reports创建了一个报告。我正在使用VisualStudio2010。当我尝试转到另一页时,问题出现了。当我尝试导航到第2页或最后一页时,屏幕上会出现“无可用的有效报告源”错误。有人知道我需要做什么吗?感谢您抽出时间

尝试在此线程中使用解决方案:


根据它所说的,您应该能够通过在代码中提供ConnectionInfo和ReportSource使其工作。

将您的报告存储在会话中,然后在返回页面上提供会话中的报告源

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;
    }

这不是什么大问题,您只需要创建数据源的会话。然后在页面加载时传递它。所有crystal报告功能将正常工作


如果您需要任何进一步的帮助或代码,请告诉我。

感谢@Răzvan Panda
这里给出了完整的代码。


以下内容可以解决您的问题:

protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            //whatever you do when the page is loaded for the first time
            //this could even be bindReport();
        }
        else
        {
            bindReport();
        }
    }

public void bindReport()
    {
        ReportDocument rptDoc = new ReportDocument();
        dsSample ds = new dsSample(); // .xsd file name
        DataTable dt = new DataTable();
        // Just set the name of data table
        dt.TableName = "Crystal Report Example";
        dt = getMostDialledNumbers(); //This function populates the DataTable
        ds.Tables[0].Merge(dt, true, MissingSchemaAction.Ignore);
        // Your .rpt file path will be below
        rptDoc.Load(Server.MapPath("mostDialledNumbers.rpt"));
        //set dataset to the report viewer.
        rptDoc.SetDataSource(ds);
        CrystalReportViewer1.ReportSource = rptDoc;
        CrystalReportViewer1.RefreshReport();
        //in case you have an UpdatePanel in your page, it needs to be updated
        UpdatePanel1.Update();
    }

正如在其他答案中所说的那样。将ReportDocument存储在会话(或其他内容)中并设置ReportSource

例如:

protected void Page_Load(object sender, EventArgs e)
{
          if (Session["ReportSource"] != null)
          {
             CrystalReportViewer1.ReportSource = (ReportDocument) Session["ReportSource"];
          }
          else
          {
             ReportDocument reportDocument = new ReportDocument();
             reportDocument.Load("MyReport.rpt");
             CrystalReportViewer1.ReportSource = reportDocument;
             Session["ReportSource"] = reportDocument;
          }
}

尝试查找报表中不包含的某些参数

通常情况下,当您在代码中插入某个参数,而您的报表不包含该参数时,就会发生这种情况

#简单解决方案 我刚刚使用CrystalReportViewer导航事件解决了这个问题

“查看报告”按钮我已将报告文档保存在会话中

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
   ' -- the ds is dataset variable containing data to be displayed in the report

    rptDoc.SetDataSource(ds)
    Session.Add("rptdoc", rptDoc)
    CrystalReportViewer1.ReportSource = rptDoc

    End Sub  
然后在CrystalReportViewer的导航事件中,我将CrystalReportViewer数据源设置为会话

Protected Sub j(ByVal source As Object, ByVal e As CrystalDecisions.Web.NavigateEventArgs) Handles CrystalReportViewer1.Navigate

    rpt.SetDataSource(ds)
    CrystalReportViewer1.ReportSource = session("rptdoc")

End Sub
因此,每次在导航到报表中的另一页之前,CrystalReportViewer数据源都会设置为会话中保存的报表文档

Protected Sub j(ByVal source As Object, ByVal e As CrystalDecisions.Web.NavigateEventArgs) Handles CrystalReportViewer1.Navigate

    rpt.SetDataSource(ds)
    CrystalReportViewer1.ReportSource = session("rptdoc")

End Sub