2016-09-25 96 views
0

這是我的代碼,運行代碼時出現錯誤,需要一些幫助!C#windows水晶報表,如何在水晶報表中編程顯示數據表

private void Form2_Load(object sender, EventArgs e) 
    { 
     string sql = "SELECT * FROM Worker "; 
     SqlConnection connection = new SqlConnection(connectonString); 
     SqlDataAdapter da = new SqlDataAdapter(sql, connection); 
     DataTable dt = new DataTable(); 

     da.Fill(dt); 
     CrystalReport1 cr = new CrystalReport1(); 
     cr.SetDataSource(dt); 

     crystalReportViewer1.ReportSource = cr; 
     crystalReportViewer1.Refresh(); 

    } 
+0

重複的問題: [如何綁定水晶報表手動創建數據集(HTTP:// stackoverflow.com/questions/8341272/how-to-bind-crystal-report-to-manually-created-dataset) –

回答

0

重複的問題: How to Bind Crystal Report to manually created Dataset

你需要做這樣的事情:

  Invoice invoice = new Invoice(); // instance of my rpt file 
      var ds = new DsBilling(); // DsBilling is mine XSD 
      var table2 = ds.Vendor; 
      var adapter2 = new VendorTableAdapter(); 
      adapter2.Fill(table2); 


      var table = ds.Bill; 
      var adapter = new BillTableAdapter(); 
      string name = cboCustReport.Text; 
      int month = int.Parse(cboRptFromMonth.SelectedItem.ToString()); 
      int year = int.Parse(cboReportFromYear.SelectedItem.ToString()); 
      adapter.Fill(table, name,month,year); 

      ds.AcceptChanges(); 

      invoice.SetDataSource(ds); 
      crystalReportViewer1.ReportSource = invoice; 
      crystalReportViewer1.RefreshReport();