asp.net中水晶报表 动态绑定问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 10:41:51
为了提高可移植性,我想在后台代码而不是在rpt文件中绑定数据信息,但要动态绑定rpt文件,需要在cs文件代码中访问它,网上说,vs新建一个CrystalReport1.rpt时,会自动生成一个CrystalReport1.cs文件,实例化一个CrystalReport1的对象就可以访问了,cr.SetDataSource(ds)完成绑定;
但是我用vs2005 ,无论如何在新建rpt文件后找不到对应的类文件,如何是好?请高手指点,不胜感激!

你要引入using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Share;
命名空间

然后
ReportDocument poRpt = new ReportDocument();
poRpt.Load(fileName);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand(sql, con);
sda.SelectCommand.ExecuteNonQuery();
DataSet ds = new DataSet();
sda.Fill(ds, "RepairRecord");
poRpt.SetDataSource(ds);
this.cryRV.ReportSource = poRpt;
就可以了,fileName是你报表的相对路径,相对于exe文件,最好把报表跟.exe文件放在一起,方便

直接访问CrystalReport1.rpt就好了。

CrystalReport1.cs是不会生成的,没有这个文件!
我可以给你个例子!