Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

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.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!!
Posted
Updated 8-Apr-15 4:10am
v5
Comments
Joan Magnet 8-Apr-15 9:08am    
In your developer environment?
MeftahDAKHEEL 8-Apr-15 9:30am    
sorry i could not understand!
Joan Magnet 8-Apr-15 10:04am    
are you trying to load the report in your machine or installing the program in another machine?
MeftahDAKHEEL 8-Apr-15 10:10am    
in my PC
Joan Magnet 8-Apr-15 10:38am    
ReportDocument Report = new ReportDocument();

// Load the report.
Report.Load(reportName);

// Preview the report.
crystalReportViewer1.ReportSource = Report;

The .ReportSource must be your ReportDocument, not the db datasource.

If fail during Load, try to load it in the designer.

1 solution

Change this line:
C#
cryRpt.Load("D:\\Graduation System\\Graduation System\\GraduationCertificate.rpt");

to
C#
cryRpt.Load(Server.MapPath("GraduationCertificate.rpt"));
 
Share this answer
 
Comments
MeftahDAKHEEL 8-Apr-15 9:28am    
but the server is not exists i face an error
KaushalJB 8-Apr-15 9:56am    
Refer this link u'll get idea : http://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath
MeftahDAKHEEL 8-Apr-15 10:16am    
Error 11 The name 'Server' does not exist in the current context D:\Graduation System\Graduation System\Form1.cs 58 29 Graduation System

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