放报表控件的页面
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 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();
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
{
private void Page_Load( object sender, System.EventArgs e)
{
try
{
//加载报表
m_Doc.Load(Server.MapPath( " .. " ) + " /report/rptDemo.rpt " );
m_Doc.Load(Server.MapPath( " .. " ) + " /report/rptDemo.rpt " );
//调用绑定报表的方法
this .MultiSearch();
}
catch (Exception errExce)
{
errExce.Message.ToString();
}
finally
{
}
}
/// <summary>
/// 报表模糊查询
/// </summary>
public string MultiSearch()
{
try
{
this .MultiSearch();
}
catch (Exception errExce)
{
errExce.Message.ToString();
}
finally
{
}
}
/// <summary>
/// 报表模糊查询
/// </summary>
public string MultiSearch()
{
try
{
//调用类的方法
this .m_clsRpt.SelectAll();
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
}
}
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()
/// 查询
/// </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
{
}
}
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
过 程 名 称: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上就可以了,然后就在报表上拖字段,画画样式,就可以了.