前提条件:你需要有VS,SQL Server 当然最重要的就是安装Crystal Report。

 

1.首先要在项目中导入【aspnet_client】文件夹,将这个文件夹拷贝到项目的更目录下。(这个文件夹组件用来在网页中显示报表)。

路径:C:\inetpub\wwwroot\aspnet_client

在ASP.NET MVC项目中如何使用Crystal Report水晶报表?

 

 

2.在项目中创建一个【Crystal Report.rpt】

在ASP.NET MVC项目中如何使用Crystal Report水晶报表?

 

 

3.在项目中创建一个数据集,命名为【UserinfoDataSet.xsd】

在ASP.NET MVC项目中如何使用Crystal Report水晶报表?

 

 

3.新建一个【Form窗体】。在工具箱总找到CrystalReportViwer控件,拖到Web窗体中。

在ASP.NET MVC项目中如何使用Crystal Report水晶报表?

 

 

4.在Web窗体加载事件中写代码。

 

 在ASP.NET MVC项目中如何使用Crystal Report水晶报表?

        //连接数据库
            string strcon = "server=.;database=DingdanggouShoping;uid=sa;pwd=3344520";
            SqlConnection conn = new SqlConnection(strcon);
            //打开数据库
            conn.Open();

            SqlDataAdapter da = new SqlDataAdapter("select * from UserInfo", conn);
            //数据集
            UserinfoDataSet ds = new UserinfoDataSet();
            da.Fill(ds, "UserInfo");
            //加载到水晶报表中
            //1.创建报表管理器对象
            ReportDocument rd = new ReportDocument();
            //加载报表
            rd.Load(Server.MapPath("~/CrystalReports/UserInfoReport.rpt"));
            //让报表绑定数据源
            rd.SetDataSource(ds);
            CrystalReportViewer1.ReportSource = rd;

 

5.可以看到已经将数据显示出来了。

在ASP.NET MVC项目中如何使用Crystal Report水晶报表?

相关文章:

  • 2021-09-20
  • 2022-12-23
  • 2021-07-15
  • 2021-08-12
  • 2022-12-23
  • 2022-01-30
  • 2021-06-10
猜你喜欢
  • 2021-05-31
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2021-11-18
相关资源
相似解决方案