MAYUR
MAYUR

Reputation: 3

Load Report Failed...crystal report error

public void Reports(string query, CrystalReportViewer crystalReportViewer1, string tblname, string rptname)
{
    con.Close();

    try {

        ReportDocument Report = new ReportDocument();
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter(query, con);
        DataSet ds = new DataSet();
        //ds.Tables.Add("Customer_Transaction_Master");
        da.Fill(ds, tblname);
        // Report.Load(System.Windows.Forms.Application.StartupPath + "\\Reports" + rptname);
        Report.Load(Application.StartupPath + "\\Reports" + rptname);
        Report.SetDataSource(ds.Tables[tblname]);
        Report.Refresh();
        crystalReportViewer1.ReportSource = Report;
        crystalReportViewer1.RefreshReport();                      
        Report.PrintOptions.PaperOrientation = PaperOrientation.Portrait;
        Report.PrintOptions.PaperSize = PaperSize.PaperA4;
        Report.PrintToPrinter(1, false, 0, 15);
        Report.Close();
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
        //throw ex;

    }
    finally
    {
        con.Close();
    }
}

***********--------- button click--------******

try
{
    frmdailyreport frdp = new frmdailyreport();
    gd.Reports("select * from tbl_bill where date='" + dailydate.Text + "' ", frdp.dailycrystal, "tbl_bill", "//daily.rpt");
    frdp.Show();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Source);
    MessageBox.Show(ex.Message);
}

but still load report failed... the thing is that, when i click on button it shows a "Load Report Failed error" and after clicking on "Ok" it shows the crystal report viewer not showing the report.

The globe.cs is my class file and the object of this class file is "gd".

Thank You.

Upvotes: 0

Views: 16226

Answers (1)

M. Adeel Khalid
M. Adeel Khalid

Reputation: 1796

Load Report Error means the report is not found which means definitely the path is wrong, put the exact path of your report within report i.e. Report.Load("C:\\Program Files\Reports\dailyReport.rpt"); if it loads it means you are giving wrong path by using Application.Startup, re-verify the path and put your report loading code within your button click just for testing and comment here whether your issue is resolved or not.

Upvotes: 1

Related Questions