I have 1 Windows Form with 1 pictureBox, 1 textBox, and 3 buttons: LoadFromFile, SaveToDB, and LoadFromDB.
Using LINQ to SQL connection in App.config and next code in the form:
private void btnLoadFromFile_Click(object sender, EventArgs e)
{
// open file dialog
OpenFileDialog open = new OpenFileDialog();
// image filters
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png";
if (open.ShowDialog() == DialogResult.OK)
{
// display image in picture box
picBox.Image = new Bitmap(open.FileName);
// image file path
textBox1.Text = open.FileName;
}
}
I could load Picture and its path to form.
Now I need to save the picture to an image type field named [BLOBData] in my table: tblBLOB (BLOBID, BLOBData). So what is the code to convert the picture to image type, and what is the code to then convert the image type to the picture to display it in the PictureBox control?
Store
Byte Arrayas blob in DataBase. some useful conversion methods:store to DB:
and load from DB: