Click here to Skip to main content
15,795,331 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I'm a new member. My English is poor!
Why is this code Load Report Failed error?
Thank you.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void SetLogin(ConnectionInfo connectioninfo,ReportDocument reportdocument)
        {
            TableLogOnInfos TbLogOnInfos = crystalReportViewer1.LogOnInfo;
            foreach (TableLogOnInfo TbLogOnInfo in TbLogOnInfos)
                TbLogOnInfo.ConnectionInfo = connectioninfo;
            Tables tables = reportdocument.Database.Tables;
            foreach (Table table in tables)
            {
                TableLogOnInfo tbllogoninfo = table.LogOnInfo;
                tbllogoninfo.ConnectionInfo = connectioninfo;
                table.ApplyLogOnInfo(tbllogoninfo);
            }         
        }       
        private void Form1_Load(object sender, EventArgs e)
        {
            ReportDocument RepDoc = new ReportDocument();
            ConnectionInfo connectioninfo = new ConnectionInfo();
            connectioninfo.ServerName = "(local)";
            connectioninfo.Password = "123";
            connectioninfo.UserID = "sa";
            connectioninfo.DatabaseName = "Gold_Database";
            string RepPach = Application.StartupPath + @"\WindowsFormsApplication2\CrystalReport2.rpt";
            crystalReportViewer1.ReportSource = RepPach; // ---------Invalid report file path ERROR
            RepDoc.Load(RepPach);
            crystalReportViewer1.ReportSource = RepDoc;
            SetLogin(connectioninfo, RepDoc);           
        }       
    }
}
Posted

CHeck that the crystal resides at the given path.
You can debug through the code, put a break point on string RepPach = Application.StartupPath + @"\WindowsFormsApplication2\CrystalReport2.rpt";, and then read the file path here.
Check if the file exists at that path.
 
Share this answer
 
C#
Application.StartupPath = "G:\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug"
//Crystal in this direction is
"G:\WindowsFormsApplication2\WindowsFormsApplication2"

//RepPach of the break point is NULL

//With this command gives error
string RepPach = Application.StartupPath + @"..\..\CrystalReport2.rpt";

--Please help me.
--Thanks.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900