winform项目对RDL报表中字段赋值,运行报错,请问如何解决?
首先在独立报表设计器中新建一个RDL报表,添加Object Provider类型的数据源然后添加数据集(手动添加了一些字段)
之后设计了报表样式,并将之保存
打开visual studio软件,新建一个winform应用项目,添加viewer控件
并将保存的RDL报表添加到项目中以及复制到项目文件夹bin目录的Debug文件中
准备用代码对表中的字段进行赋值,所以新建了一个类,类中字段与RDL报表数据集字段名称相同
然后在form1的load事件中将报表与viewer绑定,并对字段进行赋值
private void Form1_Load(object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(@"出库单.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument rptd = new GrapeCity.ActiveReports.Document.PageDocument(rpt);
rptd.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(document_LocateDataSource);
this.viewer1.LoadDocument(rptd);
}
private void document_LocateDataSource(object sender, LocateDataSourceEventArgs args)
{
args.Data = GetData();
}
private object GetData()
{
List<Message> list = new List<Message>();
list.Add(new Message()
{
ID=1000001,
ProductName="精煤",
Numbers=500,
Price=350,
DateTime=DateTime.Now.ToString(),
ClientName="万创集团"
}
);
return list;
}
但是运行后报错了,请问是什么原因呢?报错截图如下:
您好,您可以参考下面的链接进行设计:
https://help.grapecity.com.cn/pa ... tion?pageId=5968534 Bella.Yuan 发表于 2022-2-24 12:12
您好,您可以参考下面的链接进行设计:
https://help.grapecity.com.cn/pa ... tion?pageId=5968534
好的,重做一下吧 日期 字段有错误 wengMQ 发表于 2022-2-24 14:36
日期 字段有错误
:hjyzw: wengMQ 发表于 2022-2-24 14:36
日期 字段有错误
确实是,RDL用的是Date,Message类中写成DateTime,太粗心了:'( 绿葡萄 发表于 2022-2-24 16:35
确实是,RDL用的是Date,Message类中写成DateTime,太粗心了
您好,使用运行时数据源需要仔细一点哦,加油!:hjyzw:
页:
[1]