当前位置:编程学习 > C#/ASP.NET >>

关于图片上传到数据库中的问题

我数据库中的某个表的字段有一个picture字段,类型是varchar。如何实现把图片上传到这个字段中,并且要读出显示在image控件上  哪个编程高手能帮我解决一下  谢谢了 本人是菜鸟!
说明一点 并不是要使用二进制流的形式! --------------------编程问答-------------------- Image类型接收.然后传到你控件上 --------------------编程问答-------------------- 不明白该怎么接受  请高手指教! --------------------编程问答-------------------- Image1.ImageUrl=Page.ResolveUrl("~/")+字段值
 if (fileUpload.HasFile) 
        { 
            string savePath = Server.MapPath("~/upload/"); 
            if(!System.IO.Directory.Exists(savePath)) 
           {
                System.IO.Directory.CreateDirectory(savePath); 
            } 
            savePath = savePath + "\\" + fileUpload.FileName; 
            fileUpload.SaveAs(savePath);//保存
           }
sqlconnection保存路径到picture --------------------编程问答-------------------- 如何从数据库中调出来显示在Image控件上呢 --------------------编程问答-------------------- 自己写代码,重新把流整理成Image,载入控件 --------------------编程问答-------------------- 麻烦哪位高手给一段代码看看  谢谢了! --------------------编程问答-------------------- 麻烦哪位高手给一段代码看看  谢谢了! --------------------编程问答--------------------  //字节还原为图片
        private Bitmap Img(byte[] imgbyte)
        {
            //把读取出来的byte[]转化成内存流
            MemoryStream ms = new MemoryStream(imgbyte);
            //通过内存流构造一个Bitmap
            Bitmap btmp = new Bitmap(ms);
            //设置PictureBox的Image属性为刚刚通过byte[]形成的Bitmap        
            return btmp;

        }


 /// <summary>
        /// 将图片转换为字节流
        /// </summary>
        /// <param name="imgPath">图片路径</param>
        /// <returns></returns>字节数组
        private static byte[] ImgToByte(string imgPath)
        {
            FileStream fs = new FileStream(imgPath, FileMode.Open);
            byte[] imagebytes = new byte[fs.Length];
            BinaryReader br = new BinaryReader(fs);
            imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));
            return imagebytes;
        } --------------------编程问答--------------------
引用 8 楼 eastzheng1 的回复:
 //字节还原为图片
        private Bitmap Img(byte[] imgbyte)
        {
            //把读取出来的byte[]转化成内存流
            MemoryStream ms = new MemoryStream(imgbyte);
            //通过内存流构造一个Bitmap
         ……


+1 --------------------编程问答-------------------- Image1.ImageUrl=Page.ResolveUrl("~/")+字段值
 if (fileUpload.HasFile)  
  {  
  string savePath = Server.MapPath("~/upload/");  
  if(!System.IO.Directory.Exists(savePath))  
  {
  System.IO.Directory.CreateDirectory(savePath);  
  }  
  savePath = savePath + "\\" + fileUpload.FileName;  
  fileUpload.SaveAs(savePath);//保存
  }
sqlconnection保存路径到picture
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,