简体   繁体   中英

How to remove Load Report Failed Error in Crystal Reports version 10?

I am developing a simple app using Crystal Report (Version 10) and .NET Framework 4.0 as well as VS 2010; I create crystal report in c# windows application using stored procedure; my stored procedure name is "GetByCodeService" and thats parameter is "codeService".

I run my project but my project has the error "Load report failed." in the line : "RepDoc.Load(RepPath);"!

how I can solve this problem ?

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.CrystalReports.Engine;


namespace TaxiTelfoni
{
    public partial class ReportForm : Form
    {
        public ReportForm()
        {
            InitializeComponent();
        }

        private void ReportForm_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

            SqlConnection con = new SqlConnection();
            SqlCommand cmd = new SqlCommand();
            con.ConnectionString = "Data Source =.;Initial Catalog=taxi1; Integrated Security=True";
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "GetByCodeService";
            int Id = Convert.ToInt16(textBox1.Text);
            SqlParameter ld = new SqlParameter("@codeService", Id);
            cmd.Parameters.Add(ld);
            SqlDataAdapter dataadapter = new SqlDataAdapter();
            dataadapter.SelectCommand = cmd;
            DataSet ds = new DataSet();
            dataadapter.Fill(ds);

            ConnectionInfo connectionInfo = new ConnectionInfo();
            ReportDocument RepDoc = new ReportDocument();
            connectionInfo.ServerName = ".";
            connectionInfo.DatabaseName = "taxi1";
            string RepPath = Application.StartupPath + @"CrystalReport2.rpt";
            RepDoc.Load(RepPath);
            RepDoc.SetDataSource(ds);
            crystalReportViewer1.ReportSource = RepDoc;

            ParameterValues parameterValues = new ParameterValues();
            ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
            parameterDiscreteValue.Value = Id;
            parameterValues.Add(parameterDiscreteValue);
            ParameterFieldDefinitions parameterFieldDefinitions = RepDoc.DataDefinition.ParameterFields;
            ParameterFieldDefinition parameterFieldDefinition = parameterFieldDefinitions["@codeService"];
           parameterFieldDefinition.ApplyCurrentValues(parameterValues);


        }
    }
}
            ConnectionInfo connectionInfo = new ConnectionInfo();
            ReportDocument RepDoc = new ReportDocument();
            connectionInfo.ServerName = ".";
            connectionInfo.DatabaseName = "taxi1";
            string RepPath = Path.Combine(Application.StartupPath,"CrystalReport2.rpt")
            RepDoc.Load(RepPath);
            RepDoc.SetDataSource(ds);
            crystalReportViewer1.ReportSource = RepDoc;

change Application.StartupPath + @"CrystalReport2.rpt" to Path.Combine(Application.StartupPath,"CrystalReport2.rpt")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM