C#中的Crystal报表加载错误
问题描述:
我有表格(GRADUATION)访问DB,我也将Crystal Report与该表连接,我将此报告放在我项目的目录上,
项目Form1上的
我有textbox1,水晶报告查看器和按钮,单击按钮,我需要根据textbox1上的特定学生编号,将报告中的学生数据填写为我的设计:
I have access DB with Table (GRADUATION), also i made Crystal Report connected with that table and i put this report on my project's directory,
on the project Form1 i have textbox1, crystal report viewer and button with the following code when click the button i need to see the student data fill on the report as my design according to specific student number that on textbox1:
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.Odbc;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using System.Data.OleDb;
using System.Collections;
namespace Graduation
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'DSReport.GRADUATION' table. You can move, or remove it, as needed.
this.GRADUATIONTableAdapter.Fill(this.DSReport.GRADUATION);
// this.RV1.RefreshReport();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Plese Inter Student's ID");
textBox1.Focus();
}
else
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:D:\\Graduation System\\Graduation System\\bin\\Debug\\StudentsDB.mdb");
OleDbDataAdapter ad = new OleDbDataAdapter("select STDID, FName, LName, DOB, Nationality, GRADUDATE, GRADE from GRADUATION where STDID='" + textBox1.Text + "'", con);
DataSet ds = new DataSet();
ad.Fill(ds, "GRAD");
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(Application.StartupPath + "GraduationCertificate.rpt");
CRV1.ReportSource = (ds.Tables["GRAD"]);
CRV1.Refresh();
}
}
}
}
=============== ======
错误是:
加载报告失败。
加载报告时
!!
=====================
the error is:
Load report failed.
when loading the report!!
答
更改此行:
Change this line:
cryRpt.Load("D:\\Graduation System\\Graduation System\\GraduationCertificate.rpt");
to
to
cryRpt.Load(Server.MapPath("GraduationCertificate.rpt"));