cs 代码
/// <summary> /// 添加一个图片 /// </summary> public void AddImageToOracle() { AdvertisementManager am = new AdvertisementManager(); Advertisement a = new Advertisement(); string file_name = "C:\\szs.jpg"; FileStream fs = new FileStream(file_name, FileMode.OpenOrCreate, FileAccess.Read); byte[] MyData = new byte[fs.Length]; fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); a.AdImage = MyData; am.AddAdvertisement(a); } /// <summary> /// 读取一个图片 /// </summary> public void ShowImageFromOracle() { AdvertisementManager am = new AdvertisementManager(); Advertisement a = new Advertisement(); a = am.GetAdvertisementById(41); byte[] bytes = a.AdImage; Response.AppendHeader("Content-Length", bytes.Length.ToString()); Response.BinaryWrite(bytes); }
配置
普通的配置就可以
<insert id="Advertisement.Insert" parameterClass="Advertisement"> INSERT INTO AD_ADVERTISEMENT (ID,AD_NAME,AD_TYPE,AD_STATE,AD_WIDTH,AD_HEIGHT,AD_IMAGE,AD_CODE) VALUES (#Id#,#AdName#,#AdType#,#AdState#,#AdWidth#,#AdHeight#,#AdImage#,#AdCode#) <selectKey resultClass="int" type="pre" property="Id" > SELECT seq_AD_ADVERTISEMENT.NEXTVAL AS VALUE FROM DUAL </selectKey> </insert>
Po 对于大字段的对应属性,用byte[]就可以了
/// <summary> /// 图片 /// </summary> private byte[] adimage; /// <summary> /// 图片 /// </summary> public byte[] AdImage { get{return adimage;} set{adimage = value;} }
冯瑞涛