In this blog we are going to learn how to store an image into a database ( SQL Server 2008), after retrieving it from System File.
Following application s should be used
- SQL SERVER 2008.
- MICROSOFT VISUAL STUDIO 2010.
Steps to be followed in SQL SERVER 2008
- Create a database
- Create a table
Here, I created the table with the following columns
- Picture_ID
- Description
- Picture_Details
While Creating the table choose the appropriate 'Datatype'.
Steps to be followed in Microsoft Visual Studio 2010
First ,We have to Create an Windows Form Application.

Tools to be used:
- Button
- Picture box
- Label
- Text box
Command should be used
- OpenFileDialog
Code to Open the Image from the System file:
// Select the Image(s) from System File(s)
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
// Fiter,used to Filter the image in the required filetype(s)
open.Filter = Image Files(*.jpg;*.jpeg;*.gif;*.bmp)|*.jpg;*.jpeg;*.gif;*.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(open.FileName);
txtPathdirectory.Text = open.FileName;
}
}
//After Opening the Image from the
System File
Code to Insert an Image into the Database:
//Inserting an Image into the Database
private void btninsert_Click(object sender, EventArgs e)
{
SqlConnection objcon = null;
SqlCommand objcmd = null;
using (objcon = new SqlConnection("server=PC250772;initial catalog=image;user id=sa;password=password-1"))
{
try
{
objcon.Open();
string query = "insert into imageinfo (Picture_Details)values('" + txtPathdirectory.Text + "')";
objcmd = new SqlCommand(query, objcon);
int rowaffected = objcmd.ExecuteNonQuery();
MessageBox.Show("Inserted Successfully");
MessageBox.Show(rowaffected + "row'(s)" + "affected");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
//After Inserting an Image into the
Database
//Result in SQL SERVER after Inserting the Image


Deepak JerryPosted Dec 22, 2017, 2:06 AM
Open.Filter = Image Files(*.jpg;*.jpeg;*.gif;*.bmp)|*.jpg;*.jpeg;*.gif;*.bmp");
Deepak JerryPosted Dec 22, 2017, 2:06 AM
I think there is not right open.Filter = Image Files(*.jpg;*.jpeg;*.gif;*.bmp)|*.jpg;*.jpeg;*.gif;*.bmp";
vikash tiwariPosted Sep 11, 2017, 12:45 AM
Hello i get an error on this line open.Filter = Image Files(*.jpg;*.jpeg;*.gif;*.bmp)|*.jpg;*.jpeg;*.gif;*.bmp";. In this line error is coming..: please send correction [email protected]
Vikash TiwariPosted Aug 12, 2017, 9:08 AM
Hello i get an error on this line open.Filter = Image Files(*.jpg;*.jpeg;*.gif;*.bmp)|*.jpg;*.jpeg;*.gif;*.bmp";. In this line error is coming..:( Thanks you very much . Please send me an email at [email protected]
Hossein MortazaviPosted May 10, 2014, 3:00 AM
Hello could you please tell me why i get an error on this line open.Filter = Image Files(*.jpg;*.jpeg;*.gif;*.bmp)|*.jpg;*.jpeg;*.gif;*.bmp";. In this line error is coming..:( Thanks you very much . Please send me an email at [email protected]
Akshatha SalianPosted Jul 10, 2013, 2:49 AM
@ Baranidharan Thamilselvam - Why are you saving path in an image column?
Preeti AgrawallaPosted Jul 9, 2013, 10:16 AM
open.Filter = Image Files(*.jpg;*.jpeg;*.gif;*.bmp)|*.jpg;*.jpeg;*.gif;*.bmp";. In this line error is coming..:(