Windows Develop Bookmark and Share   
 index > Windows Forms General > How to insert Image into Database
 

How to insert Image into Database

Hi,

I have one image(Company Logo) in resume. At the time of inserting all values in resume, image should also insert into database. Right now its not inserting. How to achieve this?

Thanks..
Ganapatisb  Tuesday, September 15, 2009 2:05 PM

Hi,

Insert image to the database is also like saving other data. The following is an explame.

byte[] buffer;

string imagePath;

private void button1_Click(object sender, EventArgs e)

{

imagePath = @"C:\Users\### \Desktop\smile.gif";

FileStream filestream = new FileStream(imagePath, FileMode.Open);

buffer = new byte[filestream.Length];

filestream.Read(buffer, 0, (int)filestream.Length);

filestream.Close();

SqlConnection conn = new SqlConnection("Data Source=.;user = sa;password = sa;database = factory");

SqlCommand comm = new SqlCommand();

try

{

comm.Connection = conn;

comm.CommandText = "insert into ImageTest " + "(Name, image) values (@Name, @image)";

SqlParameter[] par = new SqlParameter[2];

par[0] = new SqlParameter("@name", "Smile");

par[1] = new SqlParameter("@image", buffer);

comm.Parameters.AddRange(par);

conn.Open();

comm.ExecuteNonQuery();

}

catch (Exception err)

{

MessageBox.Show(err.Message.ToString());

}

finally

{

conn.Close();

comm.Dispose();

conn.Dispose();

}

}

A useful link:

http://www.codeproject.com/KB/web-image/PicManager.aspx

Display image from database on the form

How To Display an Image from a Database in a Windows Forms PictureBox by Using Visual Basic .NET

http://support.microsoft.com/kb/321900/en-us

HOW TO: Copy a Picture from a Database Directly to a PictureBox Control with Visual C#

http://support.microsoft.com/kb/317701/en-us

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, September 22, 2009 10:22 AM
What is your data base type(sql server, oracle) and how you want to insert your image into database. You want to keep it in a table record. Please elaborate,
AUmidh  Tuesday, September 15, 2009 2:43 PM

I am using SQL server database. I dont want to keep it in table record. Here the scenario is except image(logo) all data in resume is inserting to database. i am not attaching image seperately to resume. Image will be existing in resume. At the time of saving to databse it is not saving and retrieving.

Ganapatisb  Wednesday, September 16, 2009 4:08 AM
I don't follow your word "RESUME"? is it a type of file which has photo and you want to store the complete file into database record?
AUmidh  Wednesday, September 16, 2009 5:22 PM

Hi,

Insert image to the database is also like saving other data. The following is an explame.

byte[] buffer;

string imagePath;

private void button1_Click(object sender, EventArgs e)

{

imagePath = @"C:\Users\### \Desktop\smile.gif";

FileStream filestream = new FileStream(imagePath, FileMode.Open);

buffer = new byte[filestream.Length];

filestream.Read(buffer, 0, (int)filestream.Length);

filestream.Close();

SqlConnection conn = new SqlConnection("Data Source=.;user = sa;password = sa;database = factory");

SqlCommand comm = new SqlCommand();

try

{

comm.Connection = conn;

comm.CommandText = "insert into ImageTest " + "(Name, image) values (@Name, @image)";

SqlParameter[] par = new SqlParameter[2];

par[0] = new SqlParameter("@name", "Smile");

par[1] = new SqlParameter("@image", buffer);

comm.Parameters.AddRange(par);

conn.Open();

comm.ExecuteNonQuery();

}

catch (Exception err)

{

MessageBox.Show(err.Message.ToString());

}

finally

{

conn.Close();

comm.Dispose();

conn.Dispose();

}

}

A useful link:

http://www.codeproject.com/KB/web-image/PicManager.aspx

Display image from database on the form

How To Display an Image from a Database in a Windows Forms PictureBox by Using Visual Basic .NET

http://support.microsoft.com/kb/321900/en-us

HOW TO: Copy a Picture from a Database Directly to a PictureBox Control with Visual C#

http://support.microsoft.com/kb/317701/en-us

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, September 22, 2009 10:22 AM

You can use google to search for other answers

Custom Search

More Threads

• WebBrowser control - Print method shows Print-settings dialog for PDF file
• VFPOLEDB.1 PROVIDER???
• How to guarantee modelessness in .NET Form in Class Library?
• Inconsistency in System.Drawing.Color?
• Embedded Resources problem - "Could not find any resources appropriate..."
• Winforms in Real world
• How Can I make the event of Activate Windows to run only one time?
• Haw can i draw text with different size font.(DrawString)
• WorkingSet-Size is growing to infinity ...
• PrinterResolution PrintDocument PrintPreviewDi