我的做法是数据库里只存照片对应的路径及文件名,需要显示的时候,把相应照片文件下载到本地临时文件夹,然后在picturebox里显示。

解决方案 »

  1.   

    js = "<img src=" + System.Configuration.ConfigurationManager.AppSettings["http0"].ToString() + GetImagePath(dtStep.Rows[j]["ImageId"].ToString()) + ">";dtStep.Rows[j]["ImageId"].ToString()  数据库里面存放图片名字,从webconfig里面获取图片所在路径即可。
      

  2.   

    上面说的是b/s的,c/s里面直接用图片控件,获取路径和图片名后直接赋给控件,更简单。
      

  3.   

    在问一下,在PICTUREBOX控件+OPENFILEDIALOG控件时,这样获取打开文件的路径呢?
      

  4.   

    请参照我的部分程序
    private void btnSave_Click(object sender, System.EventArgs e)
    {
    OpenFileDialog dlg = new OpenFileDialog();
    dlg.Title = "选择图片";
    dlg.Filter = "图片(*.jpg)|*.jpg|所有文件|*.*"; byte[] blob; 
    if(dlg.ShowDialog() == DialogResult.OK)
    {
    //MessageBox.Show("ok");
    Stream fs = dlg.OpenFile();
    blob = new byte[fs.Length];
    fs.Read(blob,0,int.Parse(blob.Length.ToString())); OracleConnection conn = new OracleConnection(common.OraConn);
    conn.Open(); string sql = "insert into testblob (bb,savetime) values (:bindata,:stime)";
    OracleCommand cmd = new OracleCommand();
    cmd.CommandText = sql;
    cmd.Connection = conn; OracleParameter p1 = new OracleParameter("bindata",OracleType.Blob);
    p1.Value = blob;
    cmd.Parameters.Add(p1);

    OracleParameter p2 = new OracleParameter("stime",OracleType.DateTime);
    p2.Value = DateTime.Now;
    cmd.Parameters.Add(p2);
    try
    {
    cmd.ExecuteNonQuery();
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message);
    } conn.Close(); MessageBox.Show("保存成功!");
                }

    else
    {
    MessageBox.Show("no");
    }
    } private void btnLoad_Click(object sender, System.EventArgs e)
    {
    OracleConnection conn = new OracleConnection(common.OraConn);
    conn.Open(); OracleCommand cmd = new OracleCommand();
    cmd.Connection = conn;
    cmd.CommandText = "select bb,savetime from testblob order by savetime desc"; byte[] blob = null;
    OracleDataReader reader = cmd.ExecuteReader();
    reader.Read();

    blob = (byte[])reader[0];
    lblTime.Text = ((DateTime)reader[1]).ToLongTimeString();

    reader.Close();
    conn.Close(); MemoryStream stream = new MemoryStream(blob);
    Image pic = Image.FromStream(stream);
    pictureBox1.Image = pic;
    }
    }
      

  5.   

    common.OraConn 这是公共类的字符串,例子中有两个参数
    其他大同小异,琢磨一下就能搞定了吧
      

  6.   

    我现在就想实现类似与OFFICE中 WORD 的插入图片那样,我用一个PictureBox控件,当单击控件时,在本地电脑上选择图片,选择好后就显示在PictureBox控件上,最后保存到数据库中去。
      

  7.   

    我现在在本地电脑上,已经将图片选择好了,PictureBox控件也显示出来了,怎么将它保存到数据库里呢,下次打开时,图片又要显示在PictureBox上,急用啊 ,知道的大哥们指导下我啊