rdlc怎么添加dataset,如何将参数传递给RDLC报告,并将动态创建的数据集作为其数据源...

In my Windows Forms Application, i want to create a report. i have created an .rdlc file and assigned it a "dummy" dataset as a datasource just to get the schema, as described here :

http://blogs.msdn.com/b/sqlforum/archive/2011/04/28/sql-reporting-services-ssrs-bind-dynamic-dataset-to-your-local-report-with-reportviewer.aspx[^]

i want to change datasource of my report dynamically in the code. i found many examples like the following:private DataTable getData()

{

DataSet dss = new DataSet();

string sql = "";

sql = "SELECT ID, CLIENT_ID, AGENT_ID FROM TBLMAILDELETED";

OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);

da.Fill(dss);

DataTable dt = dss.Tables[0];

return dt;

}

private void runRptViewer()

{

this.ReportViewer1.Reset();

this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");

ReportDataSource rds = new ReportDataSource("dsNewDataSet_Table", getData());

this.ReportViewer1.LocalReport.DataSources.Clear();

this.ReportViewer1.LocalReport.DataSources.Add(rds);

this.ReportViewer1.DataBind();

this.ReportViewer1.LocalReport.Refresh();

}

i want to place similar code on a button click. my question is:

if i want to add a parameter whose value is entered in a textbox on the form, what is the best way to do it?

1- should i add it in code as a parameter in my DataAdapter, and then my query will have a where-clause that uses that parameter to filter results ?

2- should i create ReportParameter and add it to my .rdlc? if so: how will that change the code? and how should that affect my DataAdapter query?

thanks in advance

解决方案u should use .rdlc paremeters to filter the data from dataset

by using setparameters to add parameters to report, like

ReportViewer ReportViewer1 = GetReportViewer();

ReportParameter[] parameters = new ReportParameter[1];

parameters[0] = new ReportParameter("Search", Name);

ReportViewer1.LocalReport.SetParameters(parameters);

by that u can filter data from dataset.

ex:

in textbox I enter data and that value can take and pass as parameter and in filter write like :

expression operator value

=Fields!UserName.Value LIKE ="*" & Parameters!Search.Value & "*"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值