将报告动态加载到报告查看器 [英] loading report to report viewer dynamically
问题描述
大家好
我正在使用reportwizard进行报告.
我正在使用MicrosoftReportViewer来显示这些报告.
我想选择要在运行时在reportviewer中显示的报告.
为此,我正在使用以下代码:
Hello All
I am using reportwizard for reports.
i am using MicrosoftReportViewer to show these reports.
i want to choose report to show in reportviewer at runtime.
for this i am using following code :
<pre>private void Report_Load(object sender, EventArgs e)<br />
{<br />
reportViewer1.ProcessingMode=ProcessingMode.Local;<br />
LocalReport lr = reportViewer1.LocalReport;<br />
lr.ReportPath = AppDomain.CurrentDomain.BaseDirectory+"..\\..\\Reports\\rptSaleHotel.rdlc";<br />
SqlDataAdapter adp = new SqlDataAdapter("HotelSale", ConfigurationManager.ConnectionStrings["cn"].ConnectionString);<br />
adp.SelectCommand.CommandType = CommandType.StoredProcedure;<br />
adp.SelectCommand.Parameters.Add("@from",SqlDbType.DateTime).Value="02-02-2011";<br />
adp.SelectCommand.Parameters.Add("@to", SqlDbType.DateTime).Value = "02-17-2011";<br />
DataSet ds = new DataSet();<br />
adp.Fill(ds);<br />
ReportDataSource rds = new ReportDataSource();<br />
this.reportViewer1.LocalReport.DataSources.Clear();<br />
rds.Value = ds.Tables[0];<br />
rds.Name = "salehotel";<br />
string st=lr.ReportPath.ToString();<br />
lr.DataSources.Add(rds); <br />
}</pre>
但它显示的报告完全空白,并显示一条消息
A datasource instance has not been supplied for the datasource ''dbTraDeskDatase_HotelSale''.
我已经检查了包含6条记录的数据集中的值.
谁能告诉我我哪里错了
在此先感谢
but it is showing totally blank report and a message
A datasource instance has not been supplied for the datasource ''dbTraDeskDatase_HotelSale''.
i have checked the value in dataset it contain 6 records.
can anyone please tell me where i am wrong
thanks in advance
推荐答案
我得到了答案.
我错了
rds.Name = "salehotel";
在这里我必须给
rds.Name = "dbTraDeskDataSet_HotelSale";
即数据源的名称.
谢谢
i got the answer.
i was wrong at
rds.Name = "salehotel";
here i have to give
rds.Name = "dbTraDeskDataSet_HotelSale";
i.e. the name of datasource.
thanks
希望 ^ ]可能会为您提供帮助.
Hope Binding-Data-to-the-ReportViewer-Control-Dynamically-in-ASPNET-2.0[^] might help you.
这篇关于将报告动态加载到报告查看器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!