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

发布于 2024-12-06 02:15:22 字数 1940 浏览 2 评论 0原文

首先让我告诉你一件事,我还从未从事过任何类型的报道工作。我已阅读有关该主题的所有相关问题和答案。但找不到任何具体的解决方案。

我的问题是我有一个非常简单的报告,我必须在其中显示数据库视图中的一行。为了拥有该行,我创建了一个业务对象(实体)。那个实体完美地支撑着我的行。我也尝试过水晶报告和 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; 
    }
}

,请给我一个解决方案,我非常需要解决方案。提前感谢所有聪明的技术极客。

First let me tell you one thing, I have never worked with any sort of reporting yet. I have read all the related question and answer on this topic. But could not find any concrete solution.

My problem is I have a very simple report to make where I have to show a row from a view from the database. In order to have that row, I have created a business object (entity). that entity is holding my row perfectly. I have tried crystal report and rdlc report as well. But at the end I will choose only one. So I have a crystal report in my solution. In my aspx form I have taken a report-viewer. but I don know how to make these three things work together, i.e. the report, the report viewer and the object or entity that is holding the information.

Now the code goes here

the name of the crystal report is FormSaleMoneyReceipt.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>

My code behind file is

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

please, please give me a solution, I am desperately in need of the solution. Thank you all the smart tech geeks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷不放纵 2024-12-13 02:15:22

您必须创建一个 ReportSource 对象并将其分配给您的报表,如 此处

CrystalReportViewerMRN.ReportSource = myReportSource;

You have to create a ReportSource object and assign that to your report, as described here.

CrystalReportViewerMRN.ReportSource = myReportSource;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文