我有以下問題。我製作了一個爲我的客戶之一生成rdlc報告的應用程序。我使用TableAdapters來填充我在這些報告中使用的DataTable。問題是我的客戶有一個新的數據庫,他希望能夠使用該應用程序來生成舊的和新的報告。我認爲有可能改變我的TableAdapter使用的連接,以便他們僅從我的客戶端選擇的數據庫中獲取數據(兩個數據庫都具有相同的模式),但我被告知不能這樣做。那麼是否可以更改rdlc報告使用的DataTable? 我怎樣才能解決這個問題如何以編程方式更改rdlc報表中的DataTables
回答
您可以使用以下代碼在運行時將任何數據表分配給rdlc。
DataTable dtTest =obj.SelectDepartment(1);//Here I am selecting the data from DB
this.reportViewer1.RefreshReport();
reportViewer1.Visible = true;
ReportDataSource rds = new ReportDataSource();
reportViewer1.Reset();
reportViewer1.ProcessingMode = ProcessingMode.Local;
LocalReport rep = reportViewer1.LocalReport;
rep.Refresh();
rep.ReportEmbeddedResource = "Report.rdlc";//Provide full path
rds.Name = "DataSet1_tblAdapter";//Provide refrerence to data set which is used to design the rdlc. (DatasetName_TableAdapterName)
rds.Value = dtTest;
rep.DataSources.Add(rds);
this.reportViewer1.RefreshReport();
當然,應該沒事改變你的數據源的報告動態
rptView.LocalReport.ReportPath = Server.MapPath("MyReportName")
rptView.LocalReport.DataSources.Add(New ReportDataSource("DataSource", "ObjectSource"))
對不起回合的代碼是VB.net,我知道你的問題被標記爲C#,但它應該是足夠
編輯相似:
如果你想要一些參數
dim listOfParams = new List(of ReportParameter);
listOfParams.Add(new ReportParameter("Param1", myValue.toString()))
listOfParams.Add(new ReportParameter("Param2", myOtherValue.toString()))
Me.rptView.LocalReport.GetParameters(listOfParams)
剛剛編碼,所以它可能是C#和VB.net的混合。
無論它在VB中,Web上都有翻譯。只有一件事,我看到你使用了Server類,但這是一個桌面應用程序,那麼等價的是什麼? – NDraskovic 2012-04-12 13:14:27
我還沒有嘗試過這一點,但我想象的只是一個字符串指向rdlc文件,像「〜/ MyReports/Report1.rdlc」 – 2012-04-12 13:18:44
好吧,謝謝,我會試試看,看看會發生什麼 – NDraskovic 2012-04-12 13:20:36
- 1. 如何以編程方式更改RDLC報表中的頁眉高度?
- 2. 如何以編程方式更改ADF表格中的樣式
- 3. 如何以編程方式更改UIView?
- 4. 如何以編程方式更改android:configChanges?
- 5. Crystal報表以編程方式更改打印機不工作
- 6. 以編程方式更改CLLocationManager權限警報中的文本
- 7. 以編程方式將RDLC報告另存爲PDF
- 8. 如何以編程方式更改列表項目的背景?
- 9. 如何以編程方式在Qt中更改網絡模式
- 10. 以編程方式更改標籤方向,編程方式
- 11. C#以編程方式創建報表
- 12. 更改R.String的值以編程方式
- 13. 以編程方式更改SCNScene的sceneNamed
- 14. 以編程方式更改R.string的值?
- 15. 如何以編程方式更改Visio中的遊標?
- 16. 如何以編程方式更改wpf窗口中的標題?
- 17. 如何以編程方式更改Access中的選項?
- 18. 如何在iphone中以編程方式更改UIkeyboard的語言?
- 19. 如何以編程方式更改TWebBrowser中的字體
- 20. 如何以編程方式更改WPF中的DockPanel?
- 21. 如何以編程方式更改Highcharts中的顏色選項?
- 22. 如何更改android中的SeekBar顏色? (以編程方式)
- 23. 如何以編程方式更改TabBarViewController中的視圖?
- 24. 如何以編程方式更改圖像中的顏色?
- 25. 如何在Xamarin.forms的CarouselPage中以編程方式更改頁面?
- 26. 如何以編程方式更改iOS中的鍵盤?
- 27. 如何以編程方式更改Windows Vista中的功能?
- 28. 如何以編程方式更改Wordpress中的菜單?
- 29. 如何以編程方式更改/替換模板中的StoryBoard?
- 30. 如何以編程方式更改RecyclerView中項目的位置?
謝謝,我在此期間設法解決了這個問題,它與您的解決方案几乎完全相同。 – NDraskovic 2012-04-16 07:30:40
需要參考:使用Microsoft.Reporting.WinForms; – tuncalik 2013-12-25 16:46:20