ASP.Net中的MS ReportViewer,如何传递参数值
在我的 ASP.Net
项目中,我添加了一个数据报告并与 Dataset 连接。
它工作正常,但有两个问题:
1)我想在按下带有 MSReportViwer 的页面上的按钮后加载报告,例如 这是显示报告按钮。目前,报告仅在表单加载时加载。
2)我想将一些参数值传递给生成报告的sql查询。
例如
其中名称=@NM 和城市=@CT
NM
和CT
的值应在同一表格的文本框中给出。之后,我按下按钮“显示报告”,它应该显示报告。
请告知如何做。 谢谢
In my ASP.Net
project, I have added a data report and connected with Dataset.
It works fine but I have two issues:
1) I want to load the report after a button on the page carrying MSReportViwer is pressed, say
it is Show Report button. At the moment report is loading just at form load.
2) I want to pass some parameter values to the sql query generating the report.
For example
Where Name=@NM and City=@CT
values of NM
and CT
shall be given in the text boxes on the same form. After this i press the button 'Show Report'
and it should display the report.
Please advise how to do it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个按钮并将其放置在表单上。双击它将创建一个单击事件:
将表适配器/数据集填充代码行移动到此事件内部(如上所示)。
至于将参数传递给数据集:
转到数据集本身并找到填充数据表的表适配器。如果您想要更改当前使用的查询以包含参数,请单击当前查询上的“配置”,如此处< /a>.
新查询类似于: select * fromcustomers where Name=@NM and City=@CT 。
然后,您需要返回到上面填充表格适配器的代码(在按下按钮时)并将其更改为从其他控件(例如文本框)获取参数:
这将导致您的报告仅显示基于结果的结果根据您提供的参数。
Create a button and place it on the form. Double clicking it will create a click event:
Move the tableadapter/dataset Fill line of code to inside this event (as seen above).
As for the passing of a parameter to the dataset:
Go to the Datset itself and find the Tableadapter that populates your Datatable. If you want to change the query you are currently using to include parameters, click configure on the current query as seen here.
The new query would resemble something like: select * from customers where Name=@NM and City=@CT .
You need to then go back to the code above where you were filling your tableadapter (in the button press) and change it to snag the parameters from your other controls, such as a text box:
This would cause your report to only display results based on the parameters you feed it.