Загрузить его в графическом окне
var _with1 = openFileDialog1;
_with1.Filter = ("Image Files |*.png; *.bmp; *.jpg;*.jpeg; *.gif;");
_with1.FilterIndex = 4;
//Reset the file name
openFileDialog1.FileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox2.Image = Image.FromFile(openFileDialog1.FileName);
}
вставить этот путь в дБ
try
{
con = new OleDbConnection(cs);
con.Open();
cmd = new OleDbCommand(cs);
string cb = "insert into colorcodes(color,pic) VALUES ('" + colorcb.Text + "','" + openFileDialog1.FileName + "' )";
cmd = new OleDbCommand(cb);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("image Saved Successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
использовать image.location, чтобы снова отобразить в графическом окне из db
try
{
con = new OleDbConnection(cs);
con.Open();
cmd = new OleDbCommand("SELECT pic from colorcodes where color= '" + colorcb.Text + "' ", con);
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
dr.Read();
pictureBox2.ImageLocation = dr[0].ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}