如何在水晶或RDLC报表中绑定c#的业务对象?

本文关键字:绑定 业务 对象 报表 水晶 RDLC | 更新日期: 2023-09-27 18:09:33

首先让我告诉你一件事,我从来没有做过任何形式的报告。我已经阅读了所有关于这个话题的相关问题和答案。但找不到任何具体的解决办法。

我的问题是我有一个非常简单的报告,使我必须从数据库的视图显示一行。为了拥有这一行,我创建了一个业务对象(实体)。那个实体很好地控制了我的位置。我也试过crystal report和rdlc report。但最后我只会选择一个。溶液中有一个晶体报告。在我的aspx表单中,我使用了一个报表查看器。但是我不知道如何使这三件事一起工作,即报表,报表查看器和保存信息的对象或实体。

现在代码在这里

水晶报表的名称是formsalemoneereceipt .rpt

my aspx page is

<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; 
    }
}

请,请给我一个解决方案,我迫切需要解决方案。

如何在水晶或RDLC报表中绑定c#的业务对象?

您必须创建一个ReportSource对象并将其分配给您的报告,如下所述。

CrystalReportViewerMRN.ReportSource = myReportSource;