使用Crystal Reports,我将主报告与年份,论文,主题绑定在子报告中,我会显示与该报告相关的书籍年份和论文。
我的问题是,在子报告中,我看到每篇论文都有相同的数据。我在一个数据集中使用这个数据表。
我正在使用以下代码:
string query = "Select subjectname ,subjectnamehindi,year, Paper , bookID From paper where unistrID='" + uniid + "' order by year,Optional,paper";
cmd = new SqlCommand(query, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet dsp = new DataSet();
da.Fill(dsp, "Main");
if (dsp.Tables[0].Rows.Count>0)
{
rpt.Load(Server.MapPath("Crys.rpt"));
rpt.SetDataSource(dsp.Tables[0]);
//Get sub report and assign datatable1 to that report
foreach (ReportObject repOp in rpt.ReportDefinition.ReportObjects)
{
if (repOp.Kind == ReportObjectKind.SubreportObject)
{
string SubRepName = ((SubreportObject)repOp).SubreportName;
ReportDocument subRepDoc = rpt.Subreports[SubRepName];
i = 0;
c = dsp.Tables[0].Rows.Count;
DataSet dsp1 = new DataSet();
while (c > 0)
{
string bookid = dsp.Tables[0].Rows[i]["bookID"].ToString();
query = "SELECT BookCode, dbo.PaperBook.SalePrice, BookName, DisplayAuthorName FROM dbo.MasterTitle INNER JOIN dbo.PaperBook ON dbo.MasterTitle.BookCode = dbo.PaperBook.BookCode where bookID='" + bookid + "'";
cmd = new SqlCommand(query, con);
da = new SqlDataAdapter(cmd);
da.Fill(dsp1, "Sub");
subRepDoc.SetDataSource(dsp1.Tables[0]);
c = c - 1;
i = i + 1;
}
}
}
CrystalReportViewer1.ReportSource = rpt;
CrystalReportViewer1.DataBind();
// Assign report to the crystal report viewer
}
如何让子报告显示每篇论文的正确数据?
答案 0 :(得分:0)
要尝试的两件事:
1)在设置子报表数据源之前清除现有的数据源:
subRepDoc.DataSourceConnections.Clear();
2)为数据集表使用唯一名称:
da.Fill(dsp1, "UNIQUENAME");
答案 1 :(得分:0)
确保按年份和纸张过滤子报告,并在子报告中再次按照您喜欢的方式绑定表格。