水晶报表pull与push方法
水晶报表pull与push方法
水晶报表pull与push方法
(1) 水晶报表push
首先:添加个 DataSet创建表连接。
其次:CrystalReport 报表 使用向导连接现有的项表。
再次:在Default中添加控件CrystalReportViewer1。
最后:写入代码,如下:
private ReportDocument oRpt;
protected void Page_Load(objectender,EventArgse)
{
oRpt = new ReportDocument();
string RptDir = Server.MapPath("CrystalReport2.rpt");
oRpt.Load(RptDir);
SqlConnectionon=newSqlConnection"server=.;database=northwind;uid=sa;pwd=;");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from categories", con); DataSet
ds = new DataSet();
da.Fill(ds, "categories");
oRpt.SetDataSource(ds);
this.CrystalReportViewer1.ReportSource = oRpt;
}
protected void Page_Load(objectender,EventArgse)
{
oRpt = new ReportDocument();
string RptDir = Server.MapPath("CrystalReport2.rpt");
oRpt.Load(RptDir);
SqlConnectionon=newSqlConnection"server=.;database=northwind;uid=sa;pwd=;");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from categories", con); DataSet
ds = new DataSet();
da.Fill(ds, "categories");
oRpt.SetDataSource(ds);
this.CrystalReportViewer1.ReportSource = oRpt;
}
(2) 水晶报表pull
1。直接创建CrystalReport 空白报表。
2。在字段资源管理器中创建新的连接
3。创建好了以后,只须拉入你所需的字段。
4。在Default中拉入控件CrystalReportViewer1。
5。代码如下:
protected void Page_Load(object sender, EventArgs e)
{
TableLogOnInfo logOnInfo = new TableLogOnInfo();
ReportDocument oRpt = new ReportDocument();
String RptDir = Server.MapPath("CrystalReport.rpt"); ; //crystalreport1.rpt文件所在的绝对路径
oRpt.Load(RptDir);
logOnInfo.ConnectionInfo.ServerName = ".";
logOnInfo.ConnectionInfo.DatabaseName = "Northwind";
logOnInfo.ConnectionInfo.UserID="sa";logOnInfo.ConnectionInfo.Password="wojiushixihuan";
oRpt.Database.Tables[0].ApplyLogOnInfo(logOnInfo);
this.CrystalReportViewer1.ReportSource = oRpt;
}
{
TableLogOnInfo logOnInfo = new TableLogOnInfo();
ReportDocument oRpt = new ReportDocument();
String RptDir = Server.MapPath("CrystalReport.rpt"); ; //crystalreport1.rpt文件所在的绝对路径
oRpt.Load(RptDir);
logOnInfo.ConnectionInfo.ServerName = ".";
logOnInfo.ConnectionInfo.DatabaseName = "Northwind";
logOnInfo.ConnectionInfo.UserID="sa";logOnInfo.ConnectionInfo.Password="wojiushixihuan";
oRpt.Database.Tables[0].ApplyLogOnInfo(logOnInfo);
this.CrystalReportViewer1.ReportSource = oRpt;
}
转自 http://blog.csdn.net/xzdiy/archive/
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc
C/S框架网