0

我在 asp.net 2010 中使用 Sap Crystal Report 它会显示错误no valid report source id available,当我使用报表查看器工具在运行时刷新报表或移动到下一页时,这是我的编码,

 Dim crdoc5 As New ReportDocument()
 Dim crtablogoninfo5 As New TableLogOnInfo
 Dim crtabs5 As Tables

 If Not IsPostBack Then
      crdoc5.Load(Server.MapPath("CrStaffrecruit.rpt"))
      Session.Add("CrStaffrecruit", crdoc5)
      CrystalReportViewer5.ReportSource = crdoc5
  Else
      CrystalReportViewer5.ReportSource = Session("CrStaffrecruit")
  End If

  crdoc5.Load(Server.MapPath("CrStaffrecruit.rpt"))
  Dim crconninfo5 As New ConnectionInfo()
  rconninfo5.ServerName = "servername"
  crconninfo5.DatabaseName = "databasename"
  crconninfo5.UserID = "sa"
  crconninfo5.Password = ""

  crtabs5 = crdoc5.Database.Tables()
  For Each crtab5 As CrystalDecisions.CrystalReports.Engine.Table In crtabs5
      crtablogoninfo5 = crtab5.LogOnInfo
      crtablogoninfo5.ConnectionInfo = crconninfo5
      crtab5.ApplyLogOnInfo(crtablogoninfo5)
  Next

  CrystalReportViewer5.ReportSource = crdoc5
  CrystalReportViewer5.RefreshReport()

如果有人知道请帮助我...在此先感谢

4

5 回答 5

1

虽然下面的代码是用 C# 编写的,但将它翻译成 VB 应该不会太难,它应该可以解决您的问题:

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("yourReportFilePath.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();
}
于 2012-05-15T13:06:53.677 回答
1

为此,请通过以下链接

http://forums.sdn.sap.com/thread.jspa?messageID=10951477ᬵ

于 2012-01-02T07:51:19.777 回答
0

通过以下链接。我用该解决方案解决了同样的问题。

http://www.aspsnippets.com/Articles/ASPNet-Crystal-Reports-13-Visual-Studio-2010-CrystalReportViewer-Search-Button-Issue---No-valid-report-source-is-available.aspx

于 2013-12-01T15:17:19.683 回答
0

我遇到了同样的问题。您在什么情况下执行您发布的代码?我问是因为经过多次调试,我发现您需要将代码放在 Page_Load 中(而不是像我以前那样做 PreRender ......)

希望这可以帮助。

于 2011-07-11T19:05:40.727 回答
0

我多次遇到此问题,解决方案是将 Report Document 变量保存在会话中,然后Page_load放入以下代码:

if (IsPostBack)
{
    if (Session["reportDocument"] != null)
    {
        ReportDocument cr = new ReportDocument();
        cr = (ReportDocument)Session["reportDocument"];
        CrystalReportViewer1.ReportSource = cr;
        CrystalReportViewer1.DataBind();
    }
}

注意:不要忘记(Session["reportDocument"])用显示按钮填充。

于 2012-06-18T20:34:25.823 回答