pgkdave Ответов: 1

Crystal reports для visual studio 2019 C# ASP.NET веб-страница возвращает пустой отчет


Я преобразовал отчет Visual Studio 2013 VB Crystal Report в версию Visual Studio 2019 crystal reports для Visual Studio, используя следующий код:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

public partial class Reports_PerCapitaSummaryRpt : System.Web.UI.Page
{
       private void ConfigureCrystalReports()
    {
        string reportPath = Server.MapPath("percapitasummary.rpt");

        ConnectionInfo connectionInfo = new ConnectionInfo();
        
        connectionInfo.ServerName = "my server";
        connectionInfo.DatabaseName = "my database";
        connectionInfo.UserID = "my username";
        connectionInfo.Password = "my password";
        CrystalReportViewer1.ReportSource = reportPath;
        SetDBLogonForReport(connectionInfo);
    }

    public void Page_Init(object sender, EventArgs e)
    {
        ConfigureCrystalReports();
    }
    private void SetDBLogonForReport(ConnectionInfo connectionInfo)
    {
        TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo;
        foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
        {
            tableLogOnInfo.ConnectionInfo = connectionInfo;
        }
    }
}

The VB production version using the VS2013 Version of Crystal reports runs with out any problem.

What I have tried:

Since no error is produced I don't have a clue as to why the report comes back blank.  If open the report file in visual studio and click preview, the report is produced.  I just cannot get it to work using the crystal viewer  

Going to the Sapwiki is next to useless, and the Sap community  does not help either, Can anyone advise what has changed between the Visual Studio 2013 version and the VS 2019 version and what I need to change in my code to get the report to work?

1 Ответов

Рейтинг:
1

nyt72

Вам нужен источник данных для отчета.
Посмотрите на пример, и вы, возможно, знаете, как это сделать.

rprt.Load(Server.MapPath("~/CrystalReport.rpt"));  
  
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");  
        SqlCommand cmd = new SqlCommand("sp_select", con);  
        SqlDataAdapter sda = new SqlDataAdapter(cmd);  
        DataSet ds = new DataSet();  
        sda.Fill(ds, "Newtbl_data");  
        rprt.SetDataSource(ds);  
        CrystalReportViewer1.ReportSource = rprt;