向orcale数据库插入图片,
table已经定义为
CREATE TABLE PIC
(
ID VARCHAR2(20)
,RRM82_PICTURE BLOB
)

解决方案 »

  1.   

    这个与Sql Server中没有什么大的区别吧。在插入命令中使用参数,图片转换为二进制流(byte []),赋给参数,执行插入命令。
      

  2.   

    http://pengyeer.javaeye.com/blog/183107
      

  3.   

    图片转换为二进制方法。。其他和SQL基本类似。如果实在些不出来。上网上找个列子。。应该有。
      

  4.   

     //选择图片
    OpenFileDialog myfile = new OpenFileDialog();
                myfile.Filter = "JPG图片|*.jpg|BMP图片|*.bmp|GIF图片|*.gif";
                myfile.Multiselect = false;
                if (myfile.ShowDialog() == DialogResult.OK)
                {//路径
                    string imgpath = myfile.FileName;
                    string IMGNAME = imgpath.Substring(imgpath.LastIndexOf("\\") + 1,
                        (imgpath.LastIndexOf(".") - imgpath.LastIndexOf("\\") - 1));                string IMGTYPE = imgpath.Substring(imgpath.LastIndexOf(".") + 1);
           
                    Bitmap bitmap = new Bitmap(myfile.OpenFile());
                    //上传的同时显示图片
                    buttonEdit_图片.Text = IMGNAME;
                    this.pictureBox1.Image = bitmap;                Bitmap image = new Bitmap(bitmap);
                    MemoryStream memStream = new MemoryStream();
                    image.Save(memStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    bytes = memStream.ToArray();
                    memStream.Close();            }//保存图片
      if (bytes != null)
                    {
                        string sql = "update Photo set **=:BlobData where **='" + textBox1.Text.ToString().Trim() + "'";
                        boperate.savecom(sql,bytes);
                    }
    //读取显示图片
     OracleDataReader dr = boperate.getread("SELECT Photo FROM ** where **='"+Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim()+"'");
                while (dr.Read())
                {
                    
                    if (dr["Photo"]==DBNull.Value)
                    {
                        Bitmap bitmap = new Bitmap(Application.StartupPath + @"\..\..\Resources\图片\\暂无图片.jpg");
                        this.pictureBox1.Image = bitmap;
                    }
                    else
                    {                                     
                        MemoryStream ms = new MemoryStream((Byte[])dr["Photo"]);
                        Bitmap images = new Bitmap(ms);
                        this.pictureBox1.Image = images;
                    }
                }
    //读取打开图片
     OracleDataReader sdr = boperate.getread("SELECT Photo FROM  ** where **='" + Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim() + "'");
                while (sdr.Read())
                {                if (sdr["Photo"] == DBNull.Value)
                    {
                        MessageBox.Show("暂无图片");
                    }
                    else
                    {
                        Byte[] bytes = new Byte[(sdr.GetBytes(0, 0, null, 0, int.MaxValue))];
                        sdr.GetBytes(0, 0, bytes, 0, bytes.Length);
                        //string filename = Path.GetRandomFileName().ToString();//随机文件名
                        string filename = Path.GetRandomFileName().ToString();//随机文件名
                        //FileStream对象将封装的文件的相对路径或绝对路径
                        //string filePath = @"f:\" +filename.Substring (filename.LastIndexOf(".")+1) + ".doc";
                        string filePath = 系统.frmMain.address + @"\" + filename.Substring(filename.LastIndexOf(".") + 1) + ".jpg";
                        FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite);
                        fs.Write(bytes, 0, bytes.Length);
                        fs.Close();
                        //sdr.Close();
                        System.Diagnostics.Process.Start(filePath);//打开图片
                    }
                }