一个水晶报表绑定DataSet的实例【原创】

本文介绍如何在 ASP.NET 应用中使用 Crystal Reports 展示报表,包括页面配置、类文件实现及存储过程调用等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如果您有任何意见,请留下您宝贵的意见以便告知
操作环境:Visual Studio.Net2003
操作系统:window Xp SP2

报表版本:Crystal Reports 10 


放报表控件的页面

1。ReportPage.ASPX

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using MedicineDetect.Class;
//导入报表的命名空间
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace ReportDemo.Web.reportPage
{
    
/// <summary>
    
/// RollList 的摘要说明。
    
/// </summary>
    public class ReportPage: System.Web.UI.Page
    {
    
    protected CrystalDecisions.Web.CrystalReportViewer rptDemo;
        
protected System.Web.UI.WebControls.Label lblStateDate;
        
protected System.Web.UI.WebControls.TextBox txtStartDate;
        
protected System.Web.UI.WebControls.Label lblEndDate;
        
protected System.Web.UI.WebControls.TextBox txtEndDate;
        
protected System.Web.UI.WebControls.Button btnSrch;
        
protected System.Web.UI.WebControls.Panel pnlSrch;
        
protected ReportDocument m_Doc = new ReportDocument();
        protected clsRpt.m_clsRpt.= new clsRpt();   //报表类

        
private void Page_Load(object sender, System.EventArgs e)
        {
            
try
            {
               //加载报表
                m_Doc.Load(Server.MapPath(
"..")+"/report/rptDemo.rpt");            
              //调用绑定报表的方法
               
this.MultiSearch();
            
 }
            
catch(Exception errExce)
            {
                  errExce.Message.ToString();
           }
            
finally
            {

            }
        }


        
        
/// <summary>
        
/// 报表模糊查询
        
/// </summary>
        public string MultiSearch()
        {    
            
try
            {
                //调用类的方法
               
this.m_clsRpt.SelectAll();
                //设置报表的数据源(DataSet)
               
this.m_Doc.SetDataSource(m_clsRpt.MyDataSet);
                
this.rptDemo.ReportSource = m_Doc;
            
                
return " ";            
            }
            
catch(Exception errExce)
            {
               
 return errExce.Message.ToString();
            }
            
finally
            {

            }
        }

        
#region Web 窗体设计器生成的代码
        
override protected void OnInit(EventArgs e)
        {
            
//
            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            
//
            InitializeComponent();
            
base.OnInit(e);
        }
        
        
/// <summary>
        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
        
/// 此方法的内容。
        
/// </summary>
        private void InitializeComponent()
        {    
          
     this.Load += new System.EventHandler(this.Page_Load);
        }
        
#endregion
      }
}

 

2。类文件: clsRpt.cs

 

    /// <summary>
        
/// 查询
        
/// </summary>
        public string SelectAll()
        {
            
try
            {
                MySqlCommand.CommandText = "sp_t_Report_SelectAll";
                MySqlCommand.CommandType 
= CommandType.StoredProcedure;

                MyDataAdapter 
= new SqlDataAdapter(MySqlCommand);
                MyDataAdapter.Fill(MyDataSet, 
"t_Report");

                
return "";
            }
            
catch(Exception errExce)
            {
             
     errExce.Message.ToString()
            }
            
finally
            {
            }
        }

 

3。存储过程  sp_t_Report_SelectAll

/*****************************************************************************
     过 程 名 称:sp_t_Report_SelectAll
     功          能:
     编          者:zhulei        时    间:2006-11-27
     修   改   人:                修改时间:
*****************************************************************************
*/
CREATE PROCEDURE [dbo].[sp_t_Report_SelectAll]
AS

BEGIN
    SELECT     
*
     FROM         t_Report
END        


GO

4。设置报表:

设置报表在这就不做具体的说明了,因为没什么,只要创建一个DataSet,将表直接拖在DataSet上就可以了,然后就在报表上拖字段,画画样式,就可以了.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值