我有以下问题。我制作了一个为我的客户之一生成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