建立子报表数据源文件:
1<?xml version="1.0" ?>
2<xs:schema id="zp" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
3 <xs:element name="zpb">
4 <xs:complexType>
5 <xs:sequence>
6 <xs:element name="zpdata" type="xs:base64Binary" minOccurs="0" />
7 </xs:sequence>
8 </xs:complexType>
9 </xs:element>
10</xs:schema>
用代码为子报表创建数据源,子报表名称为Zp,strZp即是图片的文件名:2<xs:schema id="zp" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
3 <xs:element name="zpb">
4 <xs:complexType>
5 <xs:sequence>
6 <xs:element name="zpdata" type="xs:base64Binary" minOccurs="0" />
7 </xs:sequence>
8 </xs:complexType>
9 </xs:element>
10</xs:schema>
DataSet dtsZp = new DataSet();
DataTable dtblZp = new DataTable();
dtblZp.Columns.Add("zpdata", typeof(byte[]));
DataRow drow = dtblZp.NewRow();
drow[0] = GetFileStream(strZp);
dtblZp.Rows.Add(drow);
dtsZp.Tables.Add(dtblZp);
rpt.Subreports["Zp"].SetDataSource(dtsZp);
函数GetFileStream是将文件读入到流中:DataTable dtblZp = new DataTable();
dtblZp.Columns.Add("zpdata", typeof(byte[]));
DataRow drow = dtblZp.NewRow();
drow[0] = GetFileStream(strZp);
dtblZp.Rows.Add(drow);
dtsZp.Tables.Add(dtblZp);
rpt.Subreports["Zp"].SetDataSource(dtsZp);
1 private byte[] GetFileStream(string FileName)
2 {
3 FileStream fstr = new FileStream(Server.MapPath("images/upload/zp/" + FileName), FileMode.Open);
4 BinaryReader brd = new BinaryReader(fstr);
5 byte[] b = new byte[fstr.Length];
6 b = brd.ReadBytes((int)fstr.Length);
7 fstr.Close();
8 return b;
9 }
10
2 {
3 FileStream fstr = new FileStream(Server.MapPath("images/upload/zp/" + FileName), FileMode.Open);
4 BinaryReader brd = new BinaryReader(fstr);
5 byte[] b = new byte[fstr.Length];
6 b = brd.ReadBytes((int)fstr.Length);
7 fstr.Close();
8 return b;
9 }
10