I have been searching for days and I've found a lot but it doesn't always make sense. I am trying to create a one page report in a desktop VB.NET application (using Microsoft Report & ReportViewer
so that installation of external utilities is not required on the client machine) that displays information from one record of a query (the query has multiple joins between tables and works just fine in access).
I have managed to create a datasource
with a dataset
showing the query results in the designer and have built the report to look how I like by dragging the objects from Report Data/DataSets onto the report. How do I specify at run time which record from the query I want to display?
Originally, I created a function that takes the record ID and returns a DataSet
containing the record I require, that is how my form displays the information (data edits and additions are handled separately). Is there a way I can change the datasource for the report at runtime to this function and then send the report direct to PDF or printer?
问问题
2530 次
1 回答
1
您可以使用以下代码在运行时设置数据源:
(rv1 是您正在使用的报告查看器)dim bs as bindingsource
rv1.LocalReport.DataSources.Clear()
rv1.LocalReport.ReportEmbeddedResource = "namespace.ReportName.rdlc"
bs.DataSource = dsyourdataset
bs.DataMember = "tablename"
Dim rds As New ReportDataSource
rds.Name = "nametomatchnameonreport"
rds.Value = bs
rv1.LocalReport.DataSources.Add(rds)
至于没有 GUI 直接打印,这个链接有一些你可以使用的代码。
于 2013-10-03T12:41:21.570 回答