2
我正在使用ReportViewer創建一些報告給我的Web應用程序,我想知道:如何在運行時更改/創建rldc,reportViewer對象和dataSet?
可以使用ReportViewer而無需預先創建.rdlc文件... dataSet ...和所有東東?
我要讓這些對象的情況下,在運行時設置他們的屬性,不包括太多的文件到我的應用程序(30份報告×3檔[數據集,.rdlc和的.aspx])
以下方法解釋一下我toughts的:
保護無效的Page_Load(對象發件人,EventArgs的) {
//getting the string connection
string connString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
//estabilishing connection
using (SqlConnection conn = new SqlConnection(connString))
{
string sql = @"EXEC SP_PRODUCTS"; // or another SQL command
//opening connection
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dte = new DataTable();
//filling the dataTable with the command above
adp.Fill(dte);
//closing connection
conn.Close();
//defining which report the component will render
ReportViewer1.LocalReport.ReportPath = "myReport.rdlc";
//adding the dataSource Adicionando o data source, it's important passing the same name you defined before
//at this moment, i didn't understood if the DataSource is being created populated by the dte datatable or
//if it is just binding the dte datatable to an existing dataSource named "Products
ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("Products", dte));
//without this it wont work
ReportViewer1.DataBind();
}
}
如何解決這個問題的任何想法? 在此先感謝。
感謝您的回答。可悲的是,我已經解決了這個問題,但不是我希望的方式。 我已經爲每個報告(悲傷),一個數據集(如我所願)創建了一個.rdlc文件,並提供了所有必需的tableadapters和一個webform(如我所願)。 我認爲這樣會減少處理時間,並使代碼更易於理解。不管怎樣,謝謝你! 我會將其標記爲正確的,因爲如果我4天前知道這些信息,它會幫助我。 – MMalke 2012-02-09 21:53:32