ASP.Net中的MS ReportViewer,如何传递参数值

发布于 2024-12-04 00:52:20 字数 370 浏览 2 评论 0原文

在我的 ASP.Net 项目中,我添加了一个数据报告并与 Dataset 连接。 它工作正常,但有两个问题:

1)我想在按下带有 MSReportViwer 的页面上的按钮后加载报告,例如 这是显示报告按钮。目前,报告仅在表单加载时加载。

2)我想将一些参数值传递给生成报告的sql查询。

例如

其中名称=@NM 和城市=@CT NMCT的值应在同一表格的文本框中给出。之后,我按下按钮“显示报告”,它应该显示报告。

请告知如何做。 谢谢

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伊面 2024-12-11 00:52:20

创建一个按钮并将其放置在表单上。双击它将创建一个单击事件:

private void button_Click(object sender, EventArgs e)
{
   this.thenameofyourtableadapter.Fill(this.yourdataset.thenameofyourdatatable);
                this.thenameofyourreportviewer.RefreshReport();    
}

将表适配器/数据集填充代码行移动到此事件内部(如上所示)。

至于将参数传递给数据集:

转到数据集本身并找到填充数据表的表适配器。如果您想要更改当前使用的查询以包含参数,请单击当前查询上的“配置”,如此处< /a>.

新查询类似于: select * fromcustomers where Name=@NM and City=@CT 。

然后,您需要返回到上面填充表格适配器的代码(在按下按钮时)并将其更改为从其他控件(例如文本框)获取参数:

private void button_Click(object sender, EventArgs e)
{
      this.thenameofyourtableadapter.Fill(this.yourdataset.thenameofyourdatatable,Textbox1.Text,Textbox2.Text);
                this.thenameofyourreportviewer.RefreshReport();    
}

这将导致您的报告仅显示基于结果的结果根据您提供的参数。

Create a button and place it on the form. Double clicking it will create a click event:

private void button_Click(object sender, EventArgs e)
{
   this.thenameofyourtableadapter.Fill(this.yourdataset.thenameofyourdatatable);
                this.thenameofyourreportviewer.RefreshReport();    
}

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:

private void button_Click(object sender, EventArgs e)
{
      this.thenameofyourtableadapter.Fill(this.yourdataset.thenameofyourdatatable,Textbox1.Text,Textbox2.Text);
                this.thenameofyourreportviewer.RefreshReport();    
}

This would cause your report to only display results based on the parameters you feed it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文