当前位置: 代码迷 >> ASP.NET >> ACCESS图片读取出错了高人来帮忙啊解决办法
  详细解决方案

ACCESS图片读取出错了高人来帮忙啊解决办法

热度:8703   发布时间:2013-02-25 00:00:00.0
ACCESS图片读取出错了高人来帮忙啊
Image1.Visible   =   true;
                OleDbConnection   con   =   new   OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data   source= "   +   Server.MapPath(@ "~\App_Data\DataBase.aspx "));
                string   imagename   =   " ";
                try
                {
                        con.Open();
                        OleDbCommand   com   =   new   OleDbCommand( "select   Pic_ID   from   Picture   where   Pic_ID= "   +   DropDownList1.Text   +   " ",   con);
                        OleDbDataReader   dr   =   com.ExecuteReader();
                        dr.Read();
                        MemoryStream   ms   =   new   MemoryStream((Byte[])dr[ "Pic_ID "]);
                        Bitmap   image   =   new   Bitmap(ms);
                        string   filepath   =   Server.MapPath( "Files/ ");
                        DirectoryInfo   dir   =   new   DirectoryInfo(filepath);
                        FileInfo[]   filecount   =   dir.GetFiles();
                        int   i   =   filecount.Length;
                        imagename   =   filepath   +   ((i   +   1)   +   ".jpg ");
                        image.Save(imagename);
                        dr.Close();
                        Image1.ImageUrl   =   "Files/ "   +   ((i   +   1)   +   ".jpg ");
                }
                catch   (Exception   error)
                {
                        Label1.Text   =   "处理失败!原因为: "   +   error.ToString();
                }
                finally
                {
                        con.Close();
                }
上面代码到   MemoryStream   ms   =   new   MemoryStream((Byte[])dr[ "Pic_ID "]);就报错
错误信息是:处理失败!原因为:System.InvalidCastException:   Unable   to   cast   object   of   type   'System.Int32 '   to   type   'System.Byte[] '.   at   荣誉展示_荣誉展示.Button1_Click(Object   sender,   EventArgs   e)   in   d:\My   Documents\Visual   Studio   2005\WebSites\少年宫1\荣誉展示\荣誉展示.aspx.cs:line   44     1   2
  相关解决方案