Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how to show crystal report in c# windows forms application
Posted

You need to drag CrystalReportViewer from toolbox, then set your crystal report in that viewer from upper right corner of CrystalReportViewer.
 
Share this answer
 
Comments
prashbari 4-May-15 7:03am    
i tried this code
cmd = new SqlCommand("Select * from hosp_admin", con);
da = new SqlDataAdapter(cmd);
DataSet Ds = new DataSet();

//// here my_dt is the name of the DataTable which we
//// created in the designer view.
da.Fill(Ds, "hosp_admin");
if (con.State != ConnectionState.Open)
con.Open();
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(@"C:\Users\Administrator\Desktop\Projects_cur\HospitalApp\HospitalApp\CrystalReport1.rpt");
cryRpt.SetDataSource(Ds);
//cryRpt.SetDatabaseLogon("admin", "admin123");
crystalReportViewer1.ReportSource = cryRpt;
//crystalReportViewer1.Refresh();
con.Close();
but it does not display any record
PallavSingh 4-May-15 7:12am    
is your crystal report displayed on the form?
PallavSingh 4-May-15 7:13am    
if yes, then you should create a format on your crystal report by taking a test table, then pass new datatable.
prashbari 4-May-15 7:26am    
Thank you.. It showing all data..
 
Share this answer
 
Comments
prashbari 4-May-15 7:04am    
cmd = new SqlCommand("Select * from hosp_admin", con);
da = new SqlDataAdapter(cmd);
DataSet Ds = new DataSet();

//// here my_dt is the name of the DataTable which we
//// created in the designer view.
da.Fill(Ds, "hosp_admin");
if (con.State != ConnectionState.Open)
con.Open();
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(@"C:\Users\Administrator\Desktop\Projects_cur\HospitalApp\HospitalApp\CrystalReport1.rpt");
cryRpt.SetDataSource(Ds);
//cryRpt.SetDatabaseLogon("admin", "admin123");
crystalReportViewer1.ReportSource = cryRpt;
//crystalReportViewer1.Refresh();
con.Close();

but it does not show any record

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