我想从ACCESS中读取图片的路径,然后在WINFORM中用PICTUREBOX来显示,怎么做

解决方案 »

  1.   

    用pictureBox1.Load("文件路径")就可以。
      

  2.   

    这个应该很好实现吧,将处理后的图片保存在固定的文件夹中,上传路径至数据库,然后在winform中读取路径赋值给picturebox的属性就可以了吧.
    我这里有之前做的web的案例,希望对你有所帮助.
    //上传图片的例子if (pic1.PostedFile.ContentLength > 0)
            {
                string tempFileName = "dm_" + DateTime.Now.ToString("yyyyMMddhhmmss");
                try
                {
                    string temp = FileManager.UpImage("uploads/supplier/", pic1.PostedFile, tempFileName, "no");
                    if (temp.Substring(0, 1) == "1")
                    {
                        pic_1 = tempFileName + Path.GetExtension(pic1.PostedFile.FileName);
                    }
                }
                catch
                {
                }
            }//在页面的asp控件中显示vp1.Src = "../uploads/supplier/" + model.CNSPIC;
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.OleDb;
    using System.IO;namespace OleDbImageSample
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {        }        private string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\VisualStudioProject2010\Winform\OleDbImageSample\OleDbImageSample\DB\ImagesDB.mdb";        private void button1_Click(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;            var file = openFileDialog1.FileName;            try
                {
                    using (var conn = new OleDbConnection(strConn))
                    {
                        var comm = new OleDbCommand();
                        comm.Connection = conn;
                        comm.CommandText = "insert into images (FileName, Data) values (?, ?)";
                        var p1 = new OleDbParameter();
                        p1.DbType = DbType.String;
                        p1.Value = Path.GetFileName(file);
                        comm.Parameters.Add(p1);
                        var p2 = new OleDbParameter();
                        p2.DbType = DbType.Binary;
                        p2.Value = File.ReadAllBytes(file);
                        comm.Parameters.Add(p2);
                        
                        conn.Open();
                        comm.ExecuteNonQuery();
                        MessageBox.Show("Insert Successfully");                    var adapter = new OleDbDataAdapter("select Id, FileName from images", conn);
                        var list = new DataTable();
                        adapter.Fill(list);
                        this.listBox1.DataSource = list;
                        this.listBox1.DisplayMember = "FileName";
                        this.listBox1.ValueMember = "Id";
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }        }        private void button2_Click(object sender, EventArgs e)
            {
                if (listBox1.SelectedValue == null)
                    return;
                var id = (int)listBox1.SelectedValue;
                var sql = "select data from images where id=" + id;
                using (var conn = new OleDbConnection(strConn))
                {
                    var comm = new OleDbCommand();
                    comm.CommandText = sql;
                    comm.Connection = conn;
                    conn.Open();
                    var reader = comm.ExecuteReader();
                    if (reader.Read())
                    {
                        var data = (byte[])reader.GetValue(0);
                        using (var ms = new MemoryStream(data))
                            this.pictureBox1.Image = Image.FromStream(ms);
                    }
                }
            }
        }
    }