我用下面的代码读取Northwind的Employee表的图片,调试报错:参数无效。
不知道哪位大侠能告知解决方法,感激不尽.
protected void Page_Load(object sender, EventArgs e)
    {       
        SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand("select [Photo] from Employees where EmployeeId=1", conn);
        conn.Open();
        SqlDataReader read = cmd.ExecuteReader();
        read.Read();
        byte[] bytes = (byte[])read["Photo"];
        read.Close();
        conn.Close();
        MemoryStream ms = new MemoryStream();
        ms.Write(bytes, 0, bytes.Length);
        *System.Drawing.Image img = System.Drawing.Image.FromStream(ms); 
    }
打星号的地方报错。

解决方案 »

  1.   

    Northwind的Employee表里面存的是2进制数啊。
      

  2.   

    这个表比较特殊的,你要其它数据库的表就可以。或者
    byte[] bytes = (byte[])read["Photo"].Substring(某个数字);
    这个数字我忘记了,好象是64,还是多少
      

  3.   

    找到了,Employee 的 photo 里保存的是 gif 格式,因此 有 78 的偏移量!Pub 库就没这事儿!   // 78 is the size of the OLE header 
       // for Northwind images.
       // There's no header in PUBS as PUBS 
       // just contains the raw image bits.
       int offset = 78; 详见!
    http://www.ftponline.com/vsm/2002_07/online/hottips/esposito/