Sai Yang

Sai Yang

  • NA
  • 136
  • 27.4k

[C# + sql server 2012] how to implement with two subreport?

May 25 2018 5:34 AM
Hi again!
 
I using C# + SQL SERVER 2012 and crystalreport. I have a dataset1 that contains 2 datatables (tb_car and tb_tool).
 
I design a report contains subreport (cardetail) and subreport (toolwith) for both datatables. And I have two datagridview(dgvcar and dgvtool)
 
I need to send the value from two datagridviews to two datatables and display on the two subreport
 
But I don’t know how to write the code
 
There are place to writing the code like button_click event and frm_preview load event. I place my code like that.
 
Code on button_click event like:
  1. DataTable tbcar = new DataTable();  
  2. tbcar.Columns.Add("CarID");  
  3. tbcar.Columns.Add("Type");  
  4. tbcar.Columns.Add("Branch");  
  5. tbcar.Columns.Add("Year");  
  6. tbcar.Columns.Add("Color");  
  7. foreach (DataGridViewRow drgs in dgvcar.Rows)  
  8. {  
  9. tbcar.Rows.Add(drgs.Cells[0].Value, drgs.Cells[1].Value, drgs.Cells[2].Value, drgs.Cells[3].Value, drgs.Cells[4].Value);  
  10. }  
  11. DataTable tbtool = new DataTable();  
  12. tbtool.Columns.Add("TID");  
  13. tbtool.Columns.Add("CarID");  
  14. tbtool.Columns.Add("Tname");  
  15. tbtool.Columns.Add("QTY");  
  16. tbtool.Columns.Add("Date");  
  17. foreach (DataGridViewRow drg in dgvtool.Rows)  
  18. {  
  19. tbtool.Rows.Add(drg.Cells[0].Value, drg.Cells[1].Value, drg.Cells[2].Value, drg.Cells[3].Value, drg.Cells[4].Value);  
  20. }  
  21. Frm_preview fpv = new Frm_preview();  
  22. fpv.tbgetcar = tbcar;  
  23. fpv.tbgettool =tbtool;  
  24. fpv.ShowDialog();  
and how to give the code on form_load event in frm_preview.
 
I can get only one dgv value to display on report
 
my code in form load like:
  1. public DataTable tbgetcar = new DataTable();  
  2. public DataTable tbgettool= new DataTable();  
  3. private void crystalReportViewer1_Load(object sender, EventArgs e)  
  4. {  
  5. re1.Load("Rptcardetail.rpt", OpenReportMethod.OpenReportByDefault);  
  6. re1.SetDataSource(tbgetcar);  
  7. crystalReportViewer1.ReportSource = re1;  
  8. }  
This code I give like normally report. It not give me any result in what I need.
 
Could you give me any right implement in this method.
 
Much appreciate,
Thank you.

Answers (1)