如何在Crystal或rdlc报告中绑定c#的业务对象?

问题描述:

首先让我告诉你一件事,我从来没有与任何类型的报告合作过。我已阅读有关此主题的所有相关问题和答案。但找不到具体的解决办法。如何在Crystal或rdlc报告中绑定c#的业务对象?

我的问题是我有一个非常简单的报告,使我必须从数据库的视图中显示一行。为了获得该行,我创建了一个业务对象(实体)。该实体完美地保存了我的行。我也尝试过水晶报告和rdlc报告。但最终我只会选择一个。所以我的解决方案中有一份水晶报告。在我的aspx表格中,我使用了一个报表查看器。但我不知道如何使这三件事情一起工作,即报告,报告查看器和持有该信息的对象或实体。

现在的代码放在这里

晶体报告的名称是FormSaleMoneyReceipt.rpt

我的aspx页面

<form id="form1" runat="server"> 
<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource> 
<div id = "SearchPlace"> 
    <label for ="">Candidate ID:</label><asp:TextBox runat = "server" ID = "txtCandidateId"></asp:TextBox> 
    <label for ="">Form SL#:</label><asp:TextBox runat = "server" ID = "txtFormSl"></asp:TextBox> 
    <asp:Button runat = "server" ID = "btnShowReport" Text = "Show Report" 
     onclick="btnShowReport_Click" /> 
</div> 
<div id = "ReportViewrHolder"> 
    <CR:CrystalReportViewer ID="CrystalReportViewerMRN" runat="server" AutoDataBind="true" /> 
</div> 
</form> 

我的隐藏文件的代码是

protected void Page_Load(object sender, EventArgs e) 
{ 
} 

protected void btnShowReport_Click(object sender, EventArgs e) 
{ 
    int candidateId = 0; 

    string formSl = txtFormSl.Text; 
    ViewFormSaleMoneyReceiptEntity formSaleMoneyReceiptEntity = new ViewFormSaleMoneyReceiptEntity(); 
    if(txtCandidateId.Text != "") 
    { 
     candidateId = Convert.ToInt32(candidateId); 
     formSaleMoneyReceiptEntity = ViewFormSaleMoneyReceipt_DAO.GetMoneyReceiptByID(candidateId); 
     //CrystalReportViewerMRN.ReportSource = formSaleMoneyReceiptEntity; 
    } 
    if(txtFormSl.Text!="") 
    { 
     formSaleMoneyReceiptEntity = ViewFormSaleMoneyReceipt_DAO.GetMoneyReceiptByFormSL(formSl); 
     //CrystalReportViewerMRN.ReportSource = formSaleMoneyReceiptEntity; 
    } 
} 

请给我一个解决方案,我迫切需要解决方案。提前感谢所有智能科技爱好者。

您必须创建一个ReportSource对象并将其指定给您的报告,如here所述。

CrystalReportViewerMRN.ReportSource = myReportSource;