日期:2014-05-18  浏览次数:20825 次

如何显示ACCESS存储的OLE类型图片?送分

为显示ACCESS存储的OLE类型图片,使用了以下2个文件,但都没有显示出图片,网上也没找到实例,请教各位大侠指点。
VIEW3.ASPX文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="view3.aspx.cs" Inherits="view3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>无标题页</title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <asp:Image ID="Image1" runat="server" Height="185px" ImageUrl="~/view.aspx" Width="412px" />
  <asp:Image ID="Image2" runat="server" /></div>
  </form>
</body>
</html>
VIEW.ASPX.CS文件代码(VIEW.ASPX没有编写代码):
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.ComponentModel;
using System.Data.OleDb;
using System.IO;

public partial class view : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {

   
  OleDbConnection OleConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\db1.mdb");
  
  OleConn.Open();
  string ss = "select Image1 from image1 where id='26'";//读OLE对象字段IMAGE1
  OleDbCommand comm = new OleDbCommand(ss, OleConn);
  try
  {
  byte[] img = (Byte[])comm.ExecuteScalar();
  Response.BinaryWrite(img);
  Response.ContentType = "image/jpeg";
  }
  catch
  {
   
  }
  OleConn.Close();

  }
}


------解决方案--------------------
id='26' 你的 id 是文本类型的吗?
------解决方案--------------------
C# code
  public class DBHelper
    {
        //属性:数据库链接对象
        private static OleDbConnection conn;
        public static OleDbConnection Conn
        {

            get
            {
                try
                {

                    string connstr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" + "" + Application.StartupPath + @"\Database.mdb";

                    if (conn == null)
                        conn = new OleDbConnection(connstr);
                    if (conn.State == ConnectionState.Closed)
                        conn.Open();
                    if (conn.State == ConnectionState.Broken)
                    {
                        conn.Close();
                        conn.Open();
                    }
                    return conn;

                }
                catch (Exception ex)
                {

                    throw;
                }
            }
        }


        //方法:查询,DataReader
        public static OleDbDataReader GetReader(string SqlStr)
        {
            OleDbCommand cmd = new OleDbCommand(SqlStr, Conn);
            return cmd.ExecuteReader();
        }

        public static OleDbDataReader GetReader(string SqlStr, OleDbParameter[] paras)
        {
            OleDbCommand cmd = new OleDbCommand(SqlStr, Conn);
            cmd.P