5

使用 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      
}

如何让子报告显示每篇论文的正确数据?

4

2 回答 2

0

2要尝试的事情:

1)在设置子报表数据源之前清除现有数据源:

subRepDoc.DataSourceConnections.Clear();

2)为数据集表使用唯一名称:

da.Fill(dsp1, "UNIQUENAME");
于 2013-07-16T02:33:05.953 回答
0

确保按年份和纸张过滤您的子报告,并在子报告中按照您喜欢的方式再次绑定表格。

于 2016-07-20T12:54:35.280 回答