Access数据库存取图片  怎么做啊? 急!!!!!!!!!! 图片路径好像处理很麻烦 求高人指教!!我用的是C#

解决方案 »

  1.   

    路径都存了,还麻烦????
    难道用文件流读了存还简单些????UP!UP!UP!
      

  2.   

    采用OpenFileDialogue控件打开要存储的图片。试试。
      

  3.   

    //存图片
                MemoryStream stream = new MemoryStream();
                byte[] photo = null;
                Image img =  this.pictureBox1.Image;
                img.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                photo = stream.ToArray();
                stream.Close();
                string sql = "Insert into Tb (ID,Photo) Values ('1',@img)";
                OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\d.mdb");
                conn.Open();
                OleDbCommand comm = new OleDbCommand(sql, conn);
                comm.Parameters.Add("@img", OleDbType.VarBinary, photo.Length).Value = photo;
                comm.ExecuteNonQuery();
                conn.Close();
       //取图片
                string sql = "Select photo From Tb Where ID='1'";
                OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\A.mdb");
                conn.Open();
                OleDbCommand comm = new OleDbCommand(sql, conn);
                OleDbDataReader sdr = comm.ExecuteReader();
                sdr.Read();
                MemoryStream ms = new MemoryStream((byte[])sdr[0]);
                Image image = Image.FromStream(ms);
                sdr.Close();
                conn.Close();
                pictureBox1.Image = image;
       
      

  4.   

    你可以用FileStream 把数据库中的图片的二进制流取出来,然后存到一个比特数组当中,然后再用Image
    写出来。
    大体思路是这样的,代码网上都有,你可以查下。
      

  5.   

    winform中路径比较麻烦1、PictureBox控件显示图片
       显示本地图片: pictureBox1.Image = Image.FromFile(@"E:\新建文件夹\a.jpg");
       显示网络图片: pictureBox1.ImageLocation = @"http://www.baidu.com/img/logo.gif";
    winform相对路径 
      string   path   =   System.IO.Directory.GetCurrentDirectory();//获取应用程序的当前工作目录。   
      string   str1   =   Application.StartupPath;//获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称   
      string   str2   =   Application.ExecutablePath;//获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。   
      string   str3   =   Environment.CurrentDirectory;//获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。   
        
    asp.net中就方便了 string imgPath = Server.MapPath("images/" + path);
      

  6.   

    不一定要到Acess中存图片文件啊。存放文件路径,不一样吗?
    存了文件路径,就可以访问图片了。
      

  7.   

    存图片的时候 总是提示 找不到Access数据库   是不是必须要图片和库在同一目录下呀?
      

  8.   

    不行呀  用了8楼的方法  一样的  还是提示 找不到E盘下的 数据库
     我的库放在D盘  图片在E盘