using System; using System.IO; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Data.OleDb; using System.Drawing; using System.Web; using System. Web.SessionState; use system.Web.ui; use system.web.ui.webcontrols; using system.web.ui.htmlcontrols; using crystaldecisions.crystalReports.Engine; using crystaldecisions.shared;
A summary description of Namespace CRDataSet {///
private void ExportReport (ReportDocument Report, string OptionStr) {string ExportPath; ExportPath = Request.PhysicalApplicationPath "Exported //"; if (Directory.Exists (ExportPath) == false) Directory.CreateDirectory (Request.PhysicalApplicationPath "Exported // ");
REPORTDOCUMENT; DISKFILEDESTINATIONOPTIONOPTIONS = CRREPTIONS CREXPORTOTIONS = CRREPORTDocument.exportOptions;
switch (OptionStr) {case "Portable Document (PDF)": crDiskFileDestinationOptions.DiskFileName = ExportPath "PortableDoc.pdf"; crExportOptions.DestinationOptions = crDiskFileDestinationOptions; crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat; break; case "MS Word (DOC)": crDiskFileDestinationOptions.DiskFileName = ExportPath "Word.doc"; crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.WordForWindows; crExportOptions.DestinationOptions = crDiskFileDestinationOptions; break;} try {// Export the report crReportDocument.Export (); crReportDocument.Close (); Response.ClearContent (); Response.ClearHeaders (); switch (OptionStr) {case "Portable Document (PDF)": Response.ContentType = "application / pdf" Response.writefile (ExportPat) H "portabledoc.pdf"); break; case "MS Word (DOC": response.contenttype = "Application / Msword"; response.writefile (ExportPath "word.doc"); Break;}
Response.close (); response.close ();} catonse.write ("
"); response.write (Err.Message.toString ());}} private void Page_load (Object) sender, System.EventArgs e) {// Put user code to initialize the page here string connectionString = ""; connectionString = "Provider = SQLOLEDB;"; connectionString = "Server = it003; Database = pubs;"; connectionString = "User ID = sa; password ="; // Create and open a connection using the connection string adooledbconnection = new oledbconnection (connectionString); CONNECTIONSTRING
// BUILD A SQL Statement to Query The Datasource String Sqlstring = ""; Sqlstring = "Select * from authors";
// Retrieve The Data Using The SQL Statement and Existing Connection AdooledBDataAdapter = New OLEDBDataAdapter (Sqlstring, AdooledbConnection);
// Create a instance of a dataset dataset = new dataset ();
. // Fill the dataset with the data retrieved The name of the table // in the dataset must be the same as the table name in the report adoOleDbDataAdapter.Fill (dataSet, "authors");. // Create an instance of the strongly-typed report object crReportDocument = new CrystalReport1 (); // Pass the populated dataset to the report crReportDocument.SetDataSource (dataSet); // Set the viewer to the report object to be previewed CrystalReportViewer1.ReportSource = crReportDocument;.}
#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///
private void Button1_Click (object sender, System.EventArgs e) {this.crReportDocument = new CrystalReport1 (); // Pass the populated dataset to the report DataSet ds = new DataSet (); OleDbConnection con = new OleDbConnection ( "Provider = SQLOLEDB; Server = localhost; data = pubs; uid = sa; pwd = "); con.open (); oledbdataadapter ada = new oledbdataadapter (" SELECT * AUTHORS WHERE AU_ID LIKE '% 899%' ", Con); ada.fill (DS, "authors"); crreportDocument.setDataSource (DS); ExportReport (this.crreportDocument, "Portable Document (PDF)");
}}}