GBASE南大通用数据库分享-显示报表

下面的步骤使用.NET WinForm 应用程序显示报表,显示报表前,需使用 5.9.2 的步骤生成报表文件 world_report.rpt。

 1) 在工程项目中引用用于显示报表的组件 

  CrytalDecisions.CrystalReports.Engine 

  CrystalDecisions.ReportSource 

  CrystalDecisions.Shared 

  CrystalDecisions.Windows.Forms 

  2) 在用户界面上拖放一个 Viewer 控件 

  3) 在代码中引用水晶报表命名空间 

  CrystalDecisions.CrystalReports.Engine 

  4) 使用 GBaseConnection 创建连接对象 

  5) 使用 GBaseCommand 创建命令对象 

  6) 使用 GBaseDataAdapter 创建适配器对象

  7) 使用 ReportDocument 创建报表对象 

  8) 使用 DataSet 创建数据集对象 

  9) 建立命令对象与连接对象的关系 

 10) 设置命令对象的 CommandText 属性,指明查询语句 

 11) 从数据源中获取数据后使用适配器对象填充到数据集 

 12) 使用报表对象加载 world_report.rpt 文件 

 13) 设置报表对象的数据源为数据集对象 

 14) 设置 Viewer 空间的报表源为报表对象

 15) 显示在界面上 

  C# 示例: 

 using CrystalDecisions.CrystalReports.Engine; 

 using System.Data; 

 using GBase.Data.GBaseClient; 

 ReportDocument gsReport = new ReportDocument(); 

 DataSet gsData = new DataSet(); 

 GBaseConnection conn; 

 GBaseCommand cmd;

 GBaseDataAdapter gsAdapter; 

 conn = new GBaseConnection(); 

 cmd = new GBaseCommand(); 

 gsAdapter = new GBaseDataAdapter(); 

 conn.ConnectionString = "server=127.0.0.1;uid=root;" +

 "pwd=12345;database=test;";  

 try 

 { 

 cmd.CommandText = "SELECT city.name AS cityName, 

 city.population AS CityPopulation, " + "country.name, 

 country.population, country.continent " + "FROM country, city ORDER BY 

 country.continent, country.name"; 

 cmd.Connection = conn; 

 gsAdapter.SelectCommand = cmd; 

 gsAdapter.Fill(gsData); 

 gsReport.Load(@".\world_report.rpt"); 

 gsReport.SetDataSource(gsData); 

 gsViewer.ReportSource = gsReport; 

 } 

 catch (GBaseException ex)

 {

 MessageBox.Show(ex.Message, "Report could not be created", 

 MessageBoxButtons.OK, MessageBoxIcon.Error); 

 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值