ghasem deh

ghasem deh

  • NA
  • 258
  • 37.8k

How to display image from dgv in pictureBox

Aug 28 2014 6:25 AM
How to display image from dataGridView in pictureBox ?
and select next Row ... display next image ...
i use this code : (just show first image)

private void PhotoFinder()
        {
            string query = "SELECT Pic FROM Cam"; // Where ID=@i
            Con = new OleDbConnection(Connection);
            Con.Open();
            Com = new OleDbCommand();
            Com.CommandText = query;
          //  Com.Parameters.AddWithValue("@i", textBox1.Text);
            Com.Connection = Con;
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            adapter.SelectCommand = Com;
            DataTable objDataTable = new DataTable();
            adapter.Fill(objDataTable);
            Con.Close();
            byte[] arrPic = (byte[])(objDataTable.Rows[0]["Pic"]);
            MemoryStream ms = new MemoryStream(arrPic);
            try
            {
                pictureBox1.Image = Image.FromStream(ms);
            }
            catch { pictureBox1.Image = null; }
        }
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {          
            if (dataGridView1.Rows.Count > 0)
            {
                PhotoFinder();
                textBox4.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[3].Value.ToString();
                textBox5.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[1].Value.ToString();
                textBox6.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value.ToString();
                textBox1.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString();
            }
        }

when change query to "SELECT Pic FROM Cam Where ID=@i"  ... Error

Answers (1)