水晶报表动态加载磁盘图片

1、首先,我们先创建一个DataSet.xsd文件,如下图所示,这是一个表

2、查看此表的代码,注意字段LIMG的数据类型为base64Binary

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="DataSet8" targetNamespace="http://tempuri.org/DataSet8.xsd" xmlns:mstns="http://tempuri.org/DataSet8.xsd" xmlns="http://tempuri.org/DataSet8.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
  <xs:annotation>
    <xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
      <DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
        <Connections>
        </Connections>
        <Tables>
        </Tables>
        <Sources>
        </Sources>
      </DataSource>
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="DataSet8" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:Generator_UserDSName="DataSet8" msprop:Generator_DataSetName="DataSet8">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="BoxLabelTable" msprop:Generator_UserTableName="BoxLabelTable" msprop:Generator_RowDeletedName="BoxLabelTableRowDeleted" msprop:Generator_RowChangedName="BoxLabelTableRowChanged" msprop:Generator_RowClassName="BoxLabelTableRow" msprop:Generator_RowChangingName="BoxLabelTableRowChanging" msprop:Generator_RowEvArgName="BoxLabelTableRowChangeEvent" msprop:Generator_RowEvHandlerName="BoxLabelTableRowChangeEventHandler" msprop:Generator_TableClassName="BoxLabelTableDataTable" msprop:Generator_TableVarName="tableBoxLabelTable" msprop:Generator_RowDeletingName="BoxLabelTableRowDeleting" msprop:Generator_TablePropName="BoxLabelTable">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="LIMG" msprop:Generator_UserColumnName="LIMG" msprop:Generator_ColumnPropNameInRow="LIMG" msprop:Generator_ColumnVarNameInTable="columnLIMG" msprop:Generator_ColumnPropNameInTable="LIMGColumn" type="xs:base64Binary" minOccurs="0" />
              <xs:element name="SCIMG" msprop:Generator_UserColumnName="SCIMG" msprop:Generator_ColumnVarNameInTable="columnSCIMG" msprop:Generator_ColumnPropNameInRow="SCIMG" msprop:Generator_ColumnPropNameInTable="SCIMGColumn" type="xs:string" minOccurs="0" />
              <xs:element name="PO" msprop:Generator_UserColumnName="PO" msprop:Generator_ColumnVarNameInTable="columnPO" msprop:Generator_ColumnPropNameInRow="PO" msprop:Generator_ColumnPropNameInTable="POColumn" type="xs:string" minOccurs="0" />
              <xs:element name="ITEMNO" msprop:Generator_UserColumnName="ITEMNO" msprop:Generator_ColumnVarNameInTable="columnITEMNO" msprop:Generator_ColumnPropNameInRow="ITEMNO" msprop:Generator_ColumnPropNameInTable="ITEMNOColumn" type="xs:string" minOccurs="0" />
              <xs:element name="QTY" msprop:Generator_UserColumnName="QTY" msprop:Generator_ColumnVarNameInTable="columnQTY" msprop:Generator_ColumnPropNameInRow="QTY" msprop:Generator_ColumnPropNameInTable="QTYColumn" type="xs:decimal" minOccurs="0" />
              <xs:element name="NW" msprop:Generator_UserColumnName="NW" msprop:Generator_ColumnVarNameInTable="columnNW" msprop:Generator_ColumnPropNameInRow="NW" msprop:Generator_ColumnPropNameInTable="NWColumn" type="xs:decimal" minOccurs="0" />
              <xs:element name="GW" msprop:Generator_UserColumnName="GW" msprop:Generator_ColumnVarNameInTable="columnGW" msprop:Generator_ColumnPropNameInRow="GW" msprop:Generator_ColumnPropNameInTable="GWColumn" type="xs:decimal" minOccurs="0" />
              <xs:element name="MEAS" msprop:Generator_UserColumnName="MEAS" msprop:Generator_ColumnVarNameInTable="columnMEAS" msprop:Generator_ColumnPropNameInRow="MEAS" msprop:Generator_ColumnPropNameInTable="MEASColumn" type="xs:string" minOccurs="0" />
              <xs:element name="CARTONNO" msprop:Generator_UserColumnName="CARTONNO" msprop:Generator_ColumnVarNameInTable="columnCARTONNO" msprop:Generator_ColumnPropNameInRow="CARTONNO" msprop:Generator_ColumnPropNameInTable="CARTONNOColumn" type="xs:string" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

 

3、填充DataSet.xsd数据,关键代码如下:注意本案例中的DataSet.xsd的文件名为DataSet8

DataSet8 ds8 = new DataSet8();
object[] objs ={ReadImages(), Request.QueryString["SCIMG"],Request.QueryString["PO"],Request.QueryString["ITEMNO"],
            Request.QueryString["QTY"],Request.QueryString["NW"],Request.QueryString["GW"],Request.QueryString["MEAS"]};       
                
ds8.Tables["BoxLabelTable"].Rows.Add(objs);//注意此名字必须是本例步骤1中DataSet的表名


4、读取磁盘中的图片

private byte[] ReadImages()
    {
        string[] dir = Directory.GetFiles(Server.MapPath(@"~/Upload/BoxLabel/"));
        byte[] photo = null;
        foreach (string img in dir)
        {
            string imgPath = Path.GetFileName(img);
            if (imgPath.IndexOf(Request.QueryString["SCIMG"]) > -1)
            {
                FileStream fs = new FileStream(img, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                photo = br.ReadBytes((int)fs.Length);
                br.Close();
                fs.Close();
            }
        }
        return photo;        
    }

 

5、我们转到水晶报表中的设置,如图所示:

 

6、大功告成,让我们看看显示的效果

 

注意:本报表使用的是CrystalReport10,即VS2005自带的水晶报表

 

本文参考:http://www.cnblogs.com/babyt/archive/2005/04/21/142789.html

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值