title: How to insert and retrieve images in MYSQL using C#
body: <p>Is there a way to insert and retrieve images (the pic itself) in a MySQL Database using phpMyAdmin and XAMPP? I'm using C#.</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      //this button will save my pic from the picturebox to the database
      String strAddress = " Data Source = 127.0.0.1; Initial Catalog= ex; user id = root; password= ''";
      MySqlConnection sqlConn = new MySqlConnection(strAddress);
      MySqlCommand sqlcomm = new MySqlCommand();
  
      sqlConn.Open();
      sqlcomm.CommandText = "INSERT INTO ta VALUES(" + pictureBox1.Image  + "')";
      sqlcomm.CommandType = CommandType.Text;
      sqlcomm.Connection = sqlConn;
      sqlcomm.ExecuteNonQuery();
      sqlConn.Close();
      MessageBox.Show("RECORD SAVED!", "SAVING", MessageBoxButtons.OK, MessageBoxIcon.Information);
  }
  
  private void button2_Click(object sender, EventArgs e)
  {
      //this will put an image in the picturebox 
      OpenFileDialog dlg = new OpenFileDialog();
      dlg.Title = "Open Image";
      //dlg.Filter = "bmp files (*.bmp)|*.bmp";
      if (dlg.ShowDialog() == DialogResult.OK)
      {
          pictureBox1.Image = System.Drawing.Image.FromFile(dlg.FileName);
      }
      dlg.Dispose();
  }
  </code></pre>