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)
        
                con.Open();
        
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                comboBox1.Items.Add(dr["ID"]);

            }

 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)
            con1.Open()
  } // HOW TO PROCEED FURTHER ????

Try,

System.Data.OleDb.OleDbDataReader dr;
  dr = cmd.ExecuteReader();
  if(dr.Read()){
       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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.