C# .rdlc 报告 - 无法为数据集“DataSet1”创建数据读取器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15365731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.rdlc Report - Cannot create a data reader for dataset 'DataSet1'
提问by Thomas
I have created a .rdlc-Report under VS 2012 using the report wizard and added data source and dataset. When I try to render the report using the code below I get following error message:
我使用报表向导在 VS 2012 下创建了一个 .rdlc-Report,并添加了数据源和数据集。当我尝试使用下面的代码呈现报告时,我收到以下错误消息:
"Cannot create a data reader for dataset 'DataSet1'."
“无法为数据集 'DataSet1' 创建数据读取器。”
bytes = localReport.Render("PDF", sdeviceinfo, out smimetype, out sencoding, out sfilenameextension, out streamids, out myWarnings);
Thanks in advance for any suggestions!
在此先感谢您的任何建议!
回答by PM_ME_YOUR_CODE
1) Make sure that you are running on administrator mode and you have access to the SSRS server.
1) 确保您在管理员模式下运行并且您可以访问 SSRS 服务器。
2) Verify if you have set the correct dataset name or if you are properly loading and assigning it.
2) 验证您是否设置了正确的数据集名称,或者您是否正确加载和分配了它。
Please check thissample on MSDN.
请在 MSDN 上查看此示例。
Good luck!
祝你好运!
回答by icqbox
I have same problem that "Cannot create a data reader for dataset 'zzz'"
我有同样的问题“无法为数据集‘zzz’创建数据阅读器”
The answer is ReportDataSource(string xxx, DataTable yyy)
答案是 ReportDataSource(string xxx, DataTable yyy)
You should use the right name. xxx should be zzz
您应该使用正确的名称。xxx 应该是 zzz
回答by Sandeep Kumar
You unable to create ReportViewer and providing true dataset.It possible you are getting error due to parameter providing technique. You can try like this.I solved by using this way.
您无法创建 ReportViewer 并提供真实的数据集。由于参数提供技术,您可能会遇到错误。你可以这样试试,我是用这种方法解决的。
protected void btnPdf_Click(object sender, EventArgs e)
{
ReportViewer viwer = new ReportViewer();
ObjectDataSource ob = new ObjectDataSource("dataset.YourTableAdapter", "GetData");
dataset.YourTableAdapter ds = new dataset.YourTableAdapter();
string PDF = "PDF";
string ReportType = "ReportType";
Warning[] warnings = null;
string[] streamIds = null;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
string filetype = string.Empty;
viwer.SizeToReportContent = true;
viwer.LocalReport.ReportPath = "reports/report/report.rdlc";
viwer.ProcessingMode = ProcessingMode.Local;
ob.SelectParameters.Clear();
ob.SelectParameters.Add(QueryStringEnum.CompanyID, CurrentCompanyID.ToString());
ReportDataSource rds = new ReportDataSource("datasetname", (object) ds.GetData((long?)CurrentCompanyID.ToInt64());
viwer.LocalReport.DataSources.Add(rds);
viwer.LocalReport.Refresh();
byte[] bytes = viwer.LocalReport.Render("PDF", null,
out mimeType, out encoding, out extension, out streamIds, out warnings);
}
回答by Greg
My 'gotcha' was the discovery that DataSet was not the same as Dataset.
我的“问题”是发现 DataSet 与 Dataset 不同。
(Yes, I realize that I am actually admitting to this in a public forum as I hope that anyone else can avoid this silly mistake)
(是的,我意识到我实际上是在公共论坛上承认这一点的,因为我希望其他人可以避免这个愚蠢的错误)
回答by John D
I solved the problem -- my coding error -- I had omitted 'proper' parameter values from the aspx code for the SqlServerDataSource as follows...
我解决了这个问题——我的编码错误——我从 SqlServerDataSource 的 aspx 代码中省略了“正确”的参数值,如下所示......
Notice there is NO DefaultValue for parameter-name="p_CSV_VEHICLES"
请注意,参数名称=“p_CSV_VEHICLES”没有默认值
AND (it turned out) that the two parameters (="p_CSV_VGROUPS" and ="p_CSV_VEHICLES") could not pass an empty-string "" as the default value -- empty-string is invalid in the select context for these two parameters.
并且(事实证明)这两个参数(="p_CSV_VGROUPS" 和 ="p_CSV_VEHICLES")无法传递空字符串 "" 作为默认值——空字符串在这两个参数的选择上下文中无效。
After I added the DefaultValue and set the DefaultValue(s) to valid string values for each parameter, the report showed perfectly in the ReportViewer control on my web-page.
在我添加 DefaultValue 并将 DefaultValue(s) 设置为每个参数的有效字符串值后,报告完美地显示在我网页上的 ReportViewer 控件中。
Here is the original (not working) aspx-code.
这是原始(不起作用)的 aspx 代码。
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:FCI_WebMainConnectionString %>"
SelectCommand="uspRPT_CostDetailFleet" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="5" Name="p_UID_DIVISION" Type="Int32" />
<asp:Parameter DefaultValue="85" Name="p_UID_CUSTOMER" Type="Int32" />
<asp:Parameter DefaultValue="FCIFLEETGRP" Name="p_SORT_ORDER" Type="String" />
<asp:Parameter DefaultValue="" Name="p_CSV_VGROUPS" Type="String" />
<asp:Parameter Name="p_CSV_VEHICLES" Type="String" />
<asp:Parameter DbType="Date" DefaultValue="#01/01/2013#" Name="p_dtStart0" />
<asp:Parameter DbType="Date" DefaultValue="#12/31/2013#" Name="p_dtEnd0" />
</SelectParameters>
</asp:SqlDataSource>
回答by Ramesh
I also had the same problem. After my observations I identified that, the RDLC reports does need the dataset either it should has some records in it or empty object(empty object will have the meta data)
我也有同样的问题。经过我的观察,我发现 RDLC 报告确实需要数据集,要么它应该有一些记录,要么是空对象(空对象将包含元数据)
So best practice is always return a dataset with empty object (not Null
or nothing
)or with some records in it.
所以最佳实践总是返回一个带有空对象(notNull
或nothing
)或其中有一些记录的数据集。
回答by Harry.wong
reportviewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", ObjectDataSource1))
it's better you post your code how you set your datasource to the report.
最好发布您的代码如何将数据源设置为报告。
回答by niraj
Showing error cannot create data reader for data set of dataset1:
显示错误无法为 dataset1 的数据集创建数据读取器:
private void frm_report_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
reportViewer1.LocalReport.Refresh();
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.ReportEmbeddedResource = "cruds_reports.Report1.rdlc";
SqlCommand cmd = new SqlCommand("select * from tbl_info",con);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
if (dt.Rows.Count>0)
{
rds = new ReportDataSource("DataSet1", dt);
reportViewer1.LocalReport.DataSources.Add(rds);
rds.Value = dt;
reportViewer1.LocalReport.Refresh();
reportViewer1.RefreshReport();
}
else
{
return;
}
}
回答by AminGolmahalle
Please Check Your DataSet Name Is Correct.
请检查您的数据集名称是否正确。
reportDataSource = new ReportDataSource
{
Name = "DataSet1",// Check This Line. Are You Sure DataSet Name is Correct?
Value = ListData
};