如何在asp.net中创建cristal repot c# [英] how to create cristal repot in asp.net c#

查看:53
本文介绍了如何在asp.net中创建cristal repot c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的项目中创建Cristal Reports但是一切正常,但我的报告无法在Cristal Reports查看器中出现。



使用数据集



我的代码是:

i try creating Cristal Reports in my project but everything ok but my report cannot shoe in Cristal Reports viewer.

use dataset

my code is :

protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument crystalReport = new ReportDocument();
        crystalReport.Load(Server.MapPath("~/CustomerReport.rpt"));
        Customers dsCustomers = GetData("select * from customers");
        crystalReport.SetDataSource(dsCustomers);
        CrystalReportViewer1.ReportSource = crystalReport;
        CrystalReportViewer1.RefreshReport();
        
    }

    private Customers GetData(string query)
    {
        string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        SqlCommand cmd = new SqlCommand(query);
        using (SqlConnection con = new SqlConnection(conString))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;

                sda.SelectCommand = cmd;
                using (Customers dsCustomers = new Customers())
                {
                    sda.Fill(dsCustomers, "DataTable1");
                    return dsCustomers;
                }
            }
        }
    }

<CR:CrystalReportViewer ID="CrystalReportViewer1"  runat="server" AutoDataBind="true" />

推荐答案

您好,



请您可以在您的aspx页面中添加以下链接,并在Project中添加文件夹crystalreportviewer13。



从此路径复制crystalreportviewers13文件夹并添加到您的项目中并在您的aspx页面中添加链接。

C:\inetpub\wwwroot \ aspnet_client\system_web\4_0_30319\crystalreportviewers13

Hello,

Please You can Add the below link in your aspx Page and add the folder crystalreportviewer13 in Project.

Copied the crystalreportviewers13 folder from this path and add in your project and add link in your aspx Page.
C:\inetpub\wwwroot\aspnet_client\system_web\4_0_30319\crystalreportviewers13
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script src="crystalreportviewers13/js/crviewer/crv.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <cr:crystalreportviewer id="CrystalReportViewer1" runat="server" autodatabind="true" xmlns:cr="#unknown" />
        </div>
        <div>
         
        </div>
    </form>
</body>
</html>
  

protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument crystalReport = new CustomerReport();
        //crystalReport.Load(Server.MapPath("~/CustomerReport.rpt"));
        Customers dsCustomers = GetData("select * from customers");
        crystalReport.SetDataSource(dsCustomers);
        CrystalReportViewer1.ReportSource = crystalReport;
        CrystalReportViewer1.DataBind();
        CrystalReportViewer1.RefreshReport();
        
    }
 
    private Customers GetData(string query)
    {
        string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        SqlCommand cmd = new SqlCommand(query);
        using (SqlConnection con = new SqlConnection(conString))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;
 
                sda.SelectCommand = cmd;
                using (Customers dsCustomers = new Customers())
                {
                    sda.Fill(dsCustomers, "DataTable1");
                    return dsCustomers;
                }
            }
        }
    }


这篇关于如何在asp.net中创建cristal repot c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆