ReportViewer Processing

Submitted by waydevandyk on
Hi, i have a problem with the reportviewer, and i want to bind a report with a subreport, i use 2 different data bases which: - table enseignants( id,nom,prenom ...) from access data base - table HeureSupp(id, heure cr, heure TD ,...) from sql server data base I want to display the data of both entities in the same report, I have already made ​​a solution but my source code is not well organized, can anyone help me please? here is my code :
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10. using System.Data.OleDb;
  11. using Microsoft.Reporting.WinForms;
  12.  
  13. namespace reportSubreport
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. private DataTable infoenseignant = null;
  23.  
  24. private DataTable LoadHS()
  25. {
  26.  
  27. DataSet dataSet = new DataSet();
  28.  
  29. string strconnSql = @"Data Source=WAYDE-PC\SQLEXPRESS; Initial Catalog=HeureSuppl; Integrated Security=SSPI;";
  30.  
  31.  
  32. SqlDataAdapter ensAdapter = new SqlDataAdapter("select * FROM HeureSupplementaire", strconnSql);
  33.  
  34. ensAdapter.Fill(dataSet, "heuresupp4");
  35.  
  36. return dataSet.Tables[0];
  37. }
  38.  
  39. private DataTable Loadensinf()
  40. {
  41.  
  42. DataSet dataSet = new DataSet();
  43.  
  44. string strconnAccess = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source= C:\Users\wayde\Desktop\Developpemnt de l'application\Base de donnée\base vide.mdb";
  45.  
  46. OleDbDataAdapter HSAdapter = new OleDbDataAdapter("SELECT * FROM enseignant", strconnAccess);
  47.  
  48. HSAdapter.Fill(dataSet, "enseignant");
  49.  
  50. return dataSet.Tables[0];
  51. }
  52.  
  53. void SubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
  54. {
  55. if (infoenseignant == null)
  56. infoenseignant = Loadensinf();
  57. e.DataSources.Add(new ReportDataSource("enseignant", infoenseignant));
  58. }
  59.  
  60. private void Form1_Load(object sender, EventArgs e)
  61. {
  62. ReportViewer reportViewer = new ReportViewer();
  63.  
  64.  
  65.  
  66. reportViewer.ProcessingMode = ProcessingMode.Local;
  67.  
  68.  
  69.  
  70. reportViewer.LocalReport.ReportPath = @"C:\Users\wayde\Desktop\appl exemple\testcodevb\reportSubreport\reportSubreport\Report1.rdlc";
  71.  
  72.  
  73.  
  74. reportViewer.LocalReport.SubreportProcessing +=
  75. new SubreportProcessingEventHandler(SubreportProcessingEventHandler);
  76.  
  77.  
  78.  
  79. reportViewer.LocalReport.DataSources.Add(
  80. new ReportDataSource("heuresupp4", LoadHS()));
  81.  
  82.  
  83.  
  84. reportViewer.Dock = DockStyle.Fill;
  85. this.Controls.Add(reportViewer);
  86.  
  87. this.reportViewer1.RefreshReport();
  88. }
  89. }
  90. }