C#Winform - 通过RDL文件的帮助,将单个DataSet的解决方案扩展到ReportViewer Reports的多个DataSet [英] C# Winform – Extending solution working for single DataSet to Multiple DataSets for ReportViewer Reports with the help of RDL file
问题描述
我的代码是从
但是对于多数据集,它会出现以下错误:
搜索结果
- 当我查找这个错误时,我得到这个SO链接,我不知道
为什么发生同样的错误:
- 我可以看到下面链接中的代码匹配以及其中
解决方案似乎正在为他们工作:
http://www.dotnetspider.com/resources/28409-ReportViewer-with-multiple-dataset-report.aspx
在这一点上,我已经用尽了解决方案,需要帮助。
编辑:
首先是什么原因造成的? p>
为了扩展其他数据集的问题,我已经在我的RDL设计器中复制了表。设计师似乎将< rd:TypeName>
标签更改为< TypeName>
。
在这一点上,我非常感谢StackOverflow为我提供这个平台,发布我的问题和@RezaAghaei,他们在多次的情况下,在所有的细节问题上给出需要的解决方案。
正如在异常中所解决的那样, code>字段具有无效的子元素 TypeName
。
您应该使用 rd:TypeName
。例如:
<字段名称=id>
< DataField> id< / DataField>
< rd:TypeName> System.Int32< / rd:TypeName>
< / Field>
问题是第二个和下一个数据集,但是第一个数据集可以。
I had this code taken from Reza Aghaei’s solution, which had helped me solve the problem for single DataSet using Microsofts Reportviewer Control on Winforms.
Working Part:
Calling Form:
string sql = "SELECT bk_book_details.id, bk_book_details.book_id, bk_book_details.book_no, bk_book_details.book_name, bk_book_details.edition_id, bk_book_details.condition_id, bk_book_details.publication_year, bk_book_details.price, bk_book_details.purchase_price, bk_book_details.reference_no, bk_book_details.book_status, bk_book_details.purchase_id, bk_book_details.purchase_date FROM bk_book_details";
string reportLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Reports\LMS_Book_Price_Invoice.rdl";
var f = new ReportForm();
f.ReportPath = reportLocation;
DataTable dt = (DataTable)DataAdapter.Current.LoadData(sql, "LoadDataTable");
List<DataTable> lDt = new List<DataTable>();
lDt.Add(dt);
f.ReportData = new List<DataTable>(lDt);
f.ShowDialog();
Report Form:
public List<DataTable> ReportData { get; set; }
public string ReportPath { get; set; }
private void ReportForm_Load(object sender, EventArgs e) {
long numberOfDataSets = this.ReportData.Count();
if (numberOfDataSets == 0)
return;
var rds = new Microsoft.Reporting.WinForms.ReportDataSource("Data", this.ReportData[i]);
this.reportViewer1.LocalReport.DataSources.Add(rds);
reportViewer1.LocalReport.ReportPath = this.ReportPath;
this.reportViewer1.RefreshReport();
}
Which I extended to take multiple DataSets like so:
- Added the same SQL statement 3 times with addition of where condition to 3 tables added to the RDL file with 3 separate DataSets namely: Data, Data1, Data2
code after modification:
Calling Form:
string sql = "SELECT bk_book_details.id, bk_book_details.book_id, bk_book_details.book_no, bk_book_details.book_name, bk_book_details.edition_id, bk_book_details.condition_id, bk_book_details.publication_year, bk_book_details.price, bk_book_details.purchase_price, bk_book_details.reference_no, bk_book_details.book_status, bk_book_details.purchase_id, bk_book_details.purchase_date FROM bk_book_details WHERE bk_book_details.book_id<=2";
string sql1 = "SELECT bk_book_details.id, bk_book_details.book_id, bk_book_details.book_no, bk_book_details.book_name, bk_book_details.edition_id, bk_book_details.condition_id, bk_book_details.publication_year, bk_book_details.price, bk_book_details.purchase_price, bk_book_details.reference_no, bk_book_details.book_status, bk_book_details.purchase_id, bk_book_details.purchase_date FROM bk_book_details WHERE bk_book_details.book_id=4";
string sql2 = "SELECT bk_book_details.id, bk_book_details.book_id, bk_book_details.book_no, bk_book_details.book_name, bk_book_details.edition_id, bk_book_details.condition_id, bk_book_details.publication_year, bk_book_details.price, bk_book_details.purchase_price, bk_book_details.reference_no, bk_book_details.book_status, bk_book_details.purchase_id, bk_book_details.purchase_date FROM bk_book_details WHERE bk_book_details.book_id=5";
string reportLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Reports\LMS_Book_Price_Invoice_2.rdl";
var f = new ReportForm();
f.ReportPath = reportLocation;
DataTable dt = (DataTable)DataAdapter.Current.LoadData(sql, "LoadDataTable");
DataTable dt1 = (DataTable)DataAdapter.Current.LoadData(sql1, "LoadDataTable1");
DataTable dt2 = (DataTable)DataAdapter.Current.LoadData(sql2, "LoadDataTable2");
List<DataTable> lDt = new List<DataTable>();
lDt.Add(dt);
lDt.Add(dt1);
lDt.Add(dt2);
f.ReportData = new List<DataTable>(lDt);
f.ShowDialog();
Report Form:
public List<DataTable> ReportData { get; set; }
public string ReportPath { get; set; }
private void ReportForm_Load(object sender, EventArgs e) {
long numberOfDataSets = this.ReportData.Count();
if (numberOfDataSets == 0)
return;
this.reportViewer1.LocalReport.DataSources.Clear();
string dataX = "Data";
for (int i = 0 ; i < numberOfDataSets; i++) {
string DataName = dataX;
if (i != 0)
DataName += Convert.ToString(i);
/*For our case the DataName is used to provide DataSet name Data, Data1, Data2*/
var rds = new Microsoft.Reporting.WinForms.ReportDataSource(DataName, this.ReportData[i]);
this.reportViewer1.LocalReport.DataSources.Add(rds);
}
reportViewer1.LocalReport.ReportPath = this.ReportPath;
this.reportViewer1.RefreshReport();
}
After this, the code continues to work for Single DataSet like so:
However for Multiple Datasets, it gives the following error:
Search results:
- When I looked for this error, I got this SO link where I don’t know why the same error occurs:
Can not edit rdl report (2005 defination) in Vs 2008
- I can see a match for the code in the link below as well where the solution seems to be working for them:
http://www.dotnetspider.com/resources/28409-ReportViewer-with-multiple-dataset-report.aspx
At this point I have run out of solutions and need help.
Edit:
What caused the issue in the first place?
In order to extend the problem for additional datasets, I had copied the table in my RDL designer. The designer seems to change the <rd:TypeName>
tag to <TypeName>
.
At this point I am really grateful for StackOverflow for providing this platform for me to post my problems and to @RezaAghaei, who in multiple occasions has gone that extra mile to look at all the details of a problems to give a solution in times of need.
As addressed in the exception, the element Field
has invalid child element TypeName
.
You should use rd:TypeName
instead. For example:
<Field Name="id">
<DataField>id</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
The problem is with second and next data sets, but first data set is OK.
这篇关于C#Winform - 通过RDL文件的帮助,将单个DataSet的解决方案扩展到ReportViewer Reports的多个DataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!