本人没接触过报表,第一次接触!请有经验的同仁给与帮助。谢谢!
以下是代码部分,CrystalReport.rpt 里面什么字段都没有.....
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
public partial class _Default : System.Web.UI.Page
{
string sqlcon = "server=.;database=TnSys;uid=sa;pwd=sa;";
protected void Page_Load(object sender, EventArgs e)
{
bind();
}
private void bind()
{
string sql = "select * from test";
SqlConnection con = new SqlConnection(sqlcon);
//SqlCommand cmd = new SqlCommand(sql, con);
SqlDataAdapter sqldata = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sqldata.Fill(ds, "ds1");
GridView1.DataSource = ds.Tables["ds1"];
GridView1.DataBind();
//CrystalReport1.SetDataSource(ds);
//CrystalReportViewer1.ReportSource = CrystalReport1;
//CrystalReportViewer1.DataBind();
CrystalReportSource1.ReportDocument.Load(Server.MapPath("CrystalReport.rpt"));
//注意此处必需指明Dataset中的表的名称,否则会提示“您请求的报表需要更多信息.”
CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables[0]); (<- 运行到里就错了,不知道为什么)
//{?}中的参数可以不用赋值,即使赋了值也不起作用。
//CrystalReportSource1.ReportDocument.ParameterFields["Parm"].CurrentValues.AddValue("123");
CrystalReportSource1.ReportDocument.ParameterFields["sex"].CurrentValues.AddValue("报表样例!");
CrystalReportSource1.DataBind();
CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.DataBind();
}
}