使用 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
}
如何让子报告显示每篇论文的正确数据?