1: A data source for the new report DataSet.cs
 
 
 
  
  Copy Code code as follows: 
 
 
  
 
  
  Using System; 
  
Using System.Collections.Generic; 
  
Using System.Linq; 
  
Using System.Web; 
  
Using System.Data; 
  
 
 
  Namespace ********
{
public class DataSet
{
Public DataTable Creatdataset ()
{
DataTable dt = new DataTable ();
Dt. Columns.Add ("A");
Dt. Columns.Add ("B");
Dt. Columns.Add ("C");
return DT;
}
}
}
 
   
 
   
  
Specify the columns of the table you want to bind, and return to the DataTable, Creatdataset method name is random, or you can define multiple methods (different data sources) 
 
2: Design Report
 
 
The report design does not involve
 
3: The first step of the new data source added to the report to be kidnapped
 
Note: You need to refer to Interop.VBA.dll before you can make a new CS file as a data source
 
 
 
Bind the data source into the post
 
4: Direct the report to the Pdf,excel format
 
 
 
  
  Copy Code code as follows: 
 
 
  
 
 ReportViewer viewer = new ReportViewer (); 
 
Viewer. Processingmode = processingmode.local; 
 
Viewer. Localreport.reportembeddedresource = "* * * *. PAGE.REPORT.REPORT1.RDLC "; 
 
ReportDataSource rds_1 = new ReportDataSource ("DataSet1", Dtreport);//dataset1 as a source name in the report 
 
Viewer. LOCALREPORT.DATASOURCES.ADD (Rds_1); 
  
 
ReportParameter RP1 = new ReportParameter ("Parameters 1", "Value of reference 1"); 
 
ReportParameter Rp2 = new ReportParameter ("Parameters 2", "The value of the Parameters 2"); 
 
Viewer. Localreport.setparameters (new reportparameter[] {RP1, rp2}); 
 
 
  
 
 Warning[] warnings;
String[] Streamids;
String mimetype = String. Empty;
String encoding = string. Empty;
string extension = string. Empty;
  
 byte[] bytes = Viewer. Localreport.render ("Excel", NULL, out of mimetype, out of encoding, out of extension, out of streamids, out warnings);
Excel, PDF, Word format
Now this is the have all the bytes representing the PDF, the buffer it and send it to the client.
Response.Buffer = true;
Response.Clear ();
Response.ContentType = mimetype;
Response.AddHeader ("Content-disposition", "attachment; Filename=1_ "+ DateTime.Now.ToString (" yyyymmddhhssmm ") +" "+". "+ extension);
Response.BinaryWrite (bytes); Create the file
Response.Flush (); Send it to the client to download
 
  
 
5: Refer to the report (Rpresult as a report control) on the page
 
 
 
  
  Copy Code code as follows: 
 
 
  
 
 
DataTable dt = new DataTable ()//You can spell the data source 
 
ReportDataSource Repdatasource = new ReportDataSource ("DataSet1", DT); 
 
 
 
* Set the report parameters and display 
 
This.rpResut.LocalReport.ReportEmbeddedResource = "* * * *. PAGE.REPORT.REPORT1.RDLC ""; 
 
This.rpResut.LocalReport.DataSources.Clear (); 
 
THIS.RPRESUT.LOCALREPORT.DATASOURCES.ADD (Repdatasource); 
 
ReportParameter RP1 = new ReportParameter ("Parameters 1", "Value of reference 1"); 
 
ReportParameter Rp2 = new ReportParameter ("Parameters 2", "The value of the Parameters 2"); 
 
 
 
This.rpResut.LocalReport.SetParameters (new reportparameter[] {RP1, rp2}); 
 
This.rpResut.DataBind (); 
 
This.rpResut.LocalReport.Refresh (); 
 
 
 
 
At this point, the report's output and display are OK, and if you need more in-depth understanding, please see other articles