Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,

Am using crystal report in Win Forms. The record values fill in to data table, but not shown in report document.

How can recover this one?. Here my code.
How can recover this one?
C#
Query = "Select StudentId, TypeofInome, CourseName, CourseFee, BookFee, Paid, Balance, BillNo, Total, Curdate from tblInc where BillNo  = '" + InvoiceNo + "'";
                  StrPath = AppDomain.CurrentDomain.BaseDirectory + "\\Report\\myCrystalRep.rpt";
                  ReportDocument ObjRepDoc1 = new ReportDocument();
                  SqlDa = new SqlDataAdapter(Query, SqlCon);
                  DataTable dt = new DataTable();
                  dt.Clear();
                  SqlDa.Fill(dt);
                  myCrystalRep myRep = new myCrystalRep();
                  myRep .SetDataSource(dt);
                  crystalReportViewer1.ReportSource = myRep ;
                  crystalReportViewer1.Refresh();
                  ObjRepDoc1.Load(StrPath);
                  ObjRepDoc1.PrintToPrinter(NoofCopy, false, 0, 0);

Thanks in Advance
Posted
Updated 31-Mar-13 1:04am
v2
Comments
Prasad Khandekar 30-Mar-13 15:19pm    
Have a look at this CP article (http://www.codeproject.com/Articles/28899/Crystal-Report-with-DataSet-and-DataTable-using-C).

1 solution

The order of coding is wrong.
First you should load the report file & then assign the ReportDocument to CrystalReportViewer. So it should be like below.
C#
ReportDocument1.Load(StrPath);
crystalReportViewer1.ReportSource = ReportDocument1;
crystalReportViewer1.Refresh();

And there's no need for PrintToPrinter method in your code because you wanted only to view the report.
 
Share this answer
 

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