i have a database (access database) which contains id and img
column .The id column contains ID'S and img column contains their
respective images.

When the user selects a particular ID at runtimes the
picturebox should display the corresponding image...
However the problem is how to achieve this ?
Coz the Column img datatype is Text .

So do we need to
convert it into image type ?? how to do this...

private void Form1_Load(object sender, EventArgs e)
            OleDbDataReader dr = null;
            OleDbConnection con = new OleDbConnection(" ");
            OleDbCommand cmd = new OleDbCommand("Select * from image1", con); // image1 is the name of the table
            if (con.State == ConnectionState.Closed)
            dr = cmd.ExecuteReader();

            while (dr.Read())


 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            OleDbDataReader dr = null;
            OleDbConnection con1 = new OleDbConnection(" ");
            OleDbCommand cmd1 = new OleDbCommand("Select img from image1 where id = " + comboBox1.SelectedValue,con1);
            if (con1.State == ConnectionState.Closed)


System.Data.OleDb.OleDbDataReader dr;
  dr = cmd.ExecuteReader();
       byte []b=(byte [])dr.GetValue(0);
       pictureBox1.Image=  new Bitmap(new System.IO.MemoryStream(b,true));

i'm not using oleDB, well i just connect to the database in design mode and than i've got the path of my photos in the database. Then u can drag all your items into design mode. I paste a label in my design and i convert it to a string and that's the last part of my path. Than u just enter:
strImagelocation = "C:\\mapname\\" + lblNamepath.Text;
i think it's easier than oleDB...

This article has been dead for over six months. Start a new discussion instead.