我正在使用Crystal Report(第10版)开发一个简单的应用程序 .NET Framework 4.0以及VS 2010;我在c#中创建水晶报告 windows应用程序使用存储过程;我的存储过程名称 是" GetByCodeService"并且那个参数是" codeService"。
我跑了我的 项目,但我的项目有错误"加载报告失败。"在线 :" RepDoc.Load(RepPath);"!
我怎么能解决这个问题?
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);
}
}
}
答案 0 :(得分:0)
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;
将Application.StartupPath + @"CrystalReport2.rpt"
更改为Path.Combine(Application.StartupPath,"CrystalReport2.rpt")