0
就這樣吧。我有一個工作得很好的數據集模型,它從數據庫導入數據並將其提供給水晶報表。該解決方案的工作,但它是非常耗費時間,我不知道是否有這樣做的任何其他方式...有沒有更好的方法來做到這一點?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Oracle.DataAccess.Client;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string connetionString = null;
OracleConnection connection;
OracleDataAdapter OracleAdapter;
DataSet ds = new DataSet();
string firstSql = null;
connetionString = "datasoruce";
connection = new OracleConnection(connetionString);
string secondSql = "select statementnumber from erocks.statement_data_domestic";
connection.Open();
//OracleAdapter = new OracleDataAdapter(firstSql, connection);
//OracleAdapter.Fill(ds, "domestic");
OracleAdapter = new OracleDataAdapter(secondSql, connection);
OracleAdapter.Fill(ds, "statement");
connection.Close();
ReportDocument reportDoc = new ReportDocument();
reportDoc.Load(@"c:\users\desktop\statement.rpt");
DataTable stmt = ds.Tables["statement"];
string stmtnumber="";
for (int i = 0; i < stmt.Rows.Count - 1; i++)
{
stmtnumber = stmt.Rows[i][0].ToString();
firstSql = @"SELECT DISTINCT statement_header.statementnumber,
statement_details.invoicedate,
statement_details.invoicenumber,
statement_details.invoicetotal,
statement_details.doc_type,
statement_header.statementtotal,
statement_details.bunumber_ru,
statement_details.bunumber,
statement_details.description,
statement_details.reference_number,
statement_header.remto_zip,
statement_header.remto_city,
statement_header.remto_state,
statement_header.remto_mailname,
statement_header.remto_addr1,
statement_header.remto_addr2,
statement_header.remto_addr3,
statement_header.soldto_city,
statement_header.soldto_state,
statement_header.soldto_zip,
statement_header.soldto_addr1,
statement_header.soldto_addr2,
statement_header.soldto_addr3,
statement_header.balance_forward,
statement_header.statementdate,
statement_header.custid,
statement_header.custname,
statement_header.phone_prefix,
statement_header.phone_number,
statement_details.purchases,
statement_details.payments,
statement_details.misc_credit2,
statement_details.misc_credit1,
statement_header.company_number,
statement_header.statementpurchases,
statement_header.statementpayments,
statement_header.statementmisc_credit1,
statement_header.statementmisc_credit2,
statement_header.nomailnoprint,
statement_header.SOLDTOCOUNTRYCODE,
statement_header.SOLDTOCOUNTRYNAME,
statement_header.CREDITZEROFLAG
FROM STATEMENT_DATA_DOMESTIC statement_header
INNER JOIN STATEMENT_DATA_DETAILS statement_details
ON statement_header.statementnumber =
statement_details.statementnumber
where statement_header.statementnumber="+stmtnumber;
connection.Open();
OracleAdapter = new OracleDataAdapter(firstSql, connection);
OracleAdapter.Fill(ds, "domestic");
OracleAdapter.Dispose();
connection.Close();
reportDoc.SetDataSource(ds.Tables["domestic"]);
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = @"d:\pdf\"+ stmtnumber + ".pdf";
CrExportOptions = reportDoc.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
reportDoc.Export();
ds.Tables["domestic"].Clear();
}
}
}
}
什麼是費時呢?你是否瀏覽了代碼?有很多數據嗎?究竟是什麼問題? – LittleBobbyTables 2013-05-08 17:19:13
大量的數據處理時間過長,記錄我也跟數據庫的連接是打開和關閉的。我在想有沒有辦法讓我可以獲得數據表中的所有數據,以及如何複製確切的 – user2315840 2013-05-08 17:22:49
例如用數據庫中的所有數據填充ds.Tables [「domestic」]填充ds.tables [「聲明「]與所有語句編號。關閉數據庫連接。現在解析ds.tables [「statement」]中的每條記錄,僅從該語句編號的國內獲取所有相關數據,並將其放入一個將其提供給crystalreport的數據表中。 – user2315840 2013-05-08 17:28:23