Click here to Skip to main content
14,579,188 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
I converted a Visual Studio 2013 VB Crystal Report to the Visual Studio 2019 version of crystal reports for Visual Studio using the following code:
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?
Posted
Updated 28-Jun-20 20:39pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You need datasource for the report.
Look at the example and you may know that how to do it.

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;
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100