怎么读取,大概的语句是什么用什么数据结构存储图片比较好

解决方案 »

  1.   

    数据库使用 binary 类型。
    程序ado.stream读取。
      

  2.   

    access里叫OLE对象相当于sql的image/binary
      

  3.   

    看错了,不好意思。以为是VB呢。C#就更简单了,直接用Stream读取以后传给Bitmap对象就可以了。
    具体代码Google之。
      

  4.   

    FileStream读读成二进制流
    byte[]接受二进制流
    存byte【】进数据库
    数据库各使用image或binary都可以
      

  5.   

    pictureBox1.Image要怎么显示。。
      

  6.   

    string sql = "Select photo From Tb Where ID='1'";
      OleDbConnection conn = new OleDbConnection(strConn );
      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;
      

  7.   

    用Ole对象打开Access,将字段值取出后放到Byte数组中去,然后将Byte数组转换成文件流付给你的图片框就可以了。
      

  8.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.OleDb;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;using System.IO;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                pictureBox1.Image = ConMdb();
            }
            //读取Access数据库中的图片
            private Image ConMdb()
            {
                DataSet ds = new DataSet();
                //定义连接加密ACCESS数据库的字符串,数据库密码为xiangyu
                string strFilePath = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Application.StartupPath + "\\OEMInfo.mdb;Jet OLEDB:Database Password=xiangyu";
                //定义连接数据源信息数据表为Info,其中“标识”项为Ole类型,存储的为数据。
                string sql = "select * from Info";
                OleDbConnection con = new OleDbConnection(strFilePath);
                OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
                try
                {
                    da.Fill(ds);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
                finally
                {
                    con.Close();
                    con.Dispose();
                    da.Dispose();
                }
                Image image = null;
                try
                {
                    MemoryStream ms = new MemoryStream((byte[])ds.Tables[0].Rows[0]["标识"]);
                    image = Image.FromStream(ms);
                }
                catch (Exception ex)
                {
                    //image = image.Dispose();
                    //throw new Exception(ex.ToString());
                }
                return image;
            }
        }
    }
      

  9.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Data.OleDb;namespace WindowsApplication1
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    label1.Text = ofd.FileName;
                    this.pictureBox1.Image = Image.FromFile(label1.Text);
                }
            }        OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\student.mdb");
            DataSet ds = new DataSet();
            private void button2_Click(object sender, EventArgs e)
            {
                FileStream fs = new FileStream(label1.Text, FileMode.Open, FileAccess.Read);
                byte[] data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();            OleDbCommand command = new OleDbCommand();
                command.CommandText = "insert into pictureTab values(@id,@picture)";
                command.Parameters.AddWithValue("@id", textBox1.Text);
                command.Parameters.AddWithValue("@picture", data);
                command.Connection = conn;
                try
                {
                    conn.Open();
                    int i = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    conn.Close();
                    command = null;
                }
            }        private void button3_Click(object sender, EventArgs e)
            {
                OleDbCommand command = new OleDbCommand();
                command.CommandText = "select picture from pictureTab where (id = @id)";
                command.Parameters.AddWithValue("@id", textBox1.Text);
                command.Connection = conn;
                OleDbDataAdapter adapter = new OleDbDataAdapter(command);
                try
                {
                    //ds = new DataSet();
                    conn.Open();
                    adapter.Fill(ds, "picture");
                }
                catch (Exception ex)
                { MessageBox.Show(ex.ToString()); }
                finally
                {
                    conn.Close();
                    command = null;
                    adapter = null;
                }            byte[] data = (byte[])ds.Tables["picture"].Rows[0]["picture"];
                using (MemoryStream memStream = new MemoryStream(data))
                {
                    this.pictureBox1.Image = Image.FromStream(memStream);
                    ds.Tables.Clear();
                }
            }
        }
    }
    /*int id = int.Parse(textBox1.Text);
    command = new OleDbCommand();
    command.CommandText = "select picture from ?? where(id=@id)";
    command.Parameters.AddWithValue("@id", id);
    command.Connection = conn;
    conn.Open();
    OleDbDataReader reader = command.ExecuteReader();
    reader.Read();
    byte[] data = (byte[])reader["picture"];
    MemoryStream mem = new MemoryStream(data);
    pictureBox1.Image = Image.FromStream(mem);
    conn.Close();*/