//作者:段利庆 QQ:14035344 tel:13619240877
//智能IC卡射频卡水表电表热量表专家 西安米特仪表有限公司
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
public partial class CrystalReport : System.Web.UI.Page
{
private DBCustomer oData = new DBCustomer();
protected void Page_Load(object sender, EventArgs e)
{
SetReportParm();
}
/// <summary>
/// 设置默认的水晶报表参数字段值 ,如果参数字段没有赋值,将在页面中要求赋值后方能正确显示报表内容
/// </summary>
private void SetReportParm()
{
CrystalReportSource1.ReportDocument.ParameterFields["Parm"].CurrentValues.AddValue("1234567");
CrystalReportSource1.ReportDocument.ParameterFields["Title"].CurrentValues.AddValue("这时推模式的报表样例!");
}
protected void ButPush_Click(object sender, EventArgs e)
{
string strSQL = "SELECT [ID],[EmployeeID],[Caption],[Company],[Area],[Address],[dDate],[Contact],[Phone],[Mobile],[Demand],[sMemo],[State] " +
"FROM " + "Customer" + " ";
long lngCount = 0;
//注意此处必需指明Dataset中的表的名称,否则会提示“您请求的报表需要更多信息.
DataTable tTable = new DataTable("Customer");
tTable = oData.ExecuteSQL(strSQL, out lngCount);
//载入报表模板文件
CrystalReportSource1.ReportDocument.Load(Server.MapPath("CrystalReport1.rpt"));
//载入数据表
CrystalReportSource1.ReportDocument.SetDataSource(tTable);
//{?}中的参数可以不用赋值,即使赋了值也不起作用。
//参数字段赋值
CrystalReportSource1.ReportDocument.ParameterFields["Parm"].CurrentValues.AddValue("1234567");
CrystalReportSource1.ReportDocument.ParameterFields["Title"].CurrentValues.AddValue("这时推模式的报表样例!");
CrystalReportSource1.DataBind();
CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.DataBind();
}
}