Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends,

Well I am working on project called Employe Record Management. Now here i wants to insert all the records of and employes including their PictureImage. I am done with the insert other records like Firstname Lastname etc but now i stuck in inserting Image in to Excel Database. Pleease Hellp me to write the Query of inserting Image.
The Code which i am using to store image is as follow..

C#
pictureBox_Profile_Picture.Image.Save(FilePath,System.Drawing.Imaging.ImageFormat.Jpeg)


but its not working.. Please help me with some another code.

Thanks in advance :)
Posted
Comments
Sergey Alexandrovich Kryukov 22-Jan-13 1:34am    
Why, why PictureBox?!
—SA
Nikhil@123 22-Jan-13 1:50am    
Because i am umplaoding image from System and storing it in picturebox and then on button click evnt storing that image in to Excel file.

private void insertImage()
     {
         Excel.Application ThisApplication = new Excel.Application();
         Excel.Workbook ThisWorkBook;
         string _stFileName = "C:\\Users\\Rupam\\Desktop\\Test.xlsx";
         string _stLOGO = "D:\\LOGO.bmp";

         object missing = System.Reflection.Missing.Value;

         try
         {
             ThisWorkBook = ThisApplication.Workbooks.Open(_stFileName, missing, missing, 5, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

             Excel.Worksheet ThisSheet = (Excel.Worksheet)ThisWorkBook.Sheets[1];

             Excel.Range oRange = (Excel.Range)ThisSheet.Cells[10, 1];

             Image oImage = pictureBox1.Image;
             System.Windows.Forms.Clipboard.SetDataObject(oImage, true);
             ThisSheet.Paste(oRange, _stLOGO);

             ThisWorkBook.Save();
         }
         catch (Exception oEx)
         { MessageBox.Show(oEx.Message); }
         finally
         {
             ThisApplication.Quit();
             ThisWorkBook = null;
             ThisApplication = null;
         }
     }


See the msdn post here:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/5bb5eb47-ea5e-4d97-a794-6266122552ea[^]
 
Share this answer
 
Comments
Nikhil@123 22-Jan-13 1:53am    
Thanks For Reply Sir, Would you mind? explaining me this part of code..

ThisWorkBook = ThisApplication.Workbooks.Open(_stFileName, missing, missing, 5, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

Please.
Nikhil@123 22-Jan-13 3:27am    
Good to see your msg again,,, Well the given code has worked nicely.... but i dint see any image inserting in the ma Excel Database. What would be the problem. And there was not even any exception. i wants to insert image in column "O".
Important: Also include Microsoft Excell Object Library from Add Reference-> Com tab and Microsoft Office object Library

Also

using Excel = Microsoft.Office.Interop.Excel;



use the above line at the top of code in namespace section.

As par explanation, read through some documents to get an overview of how stuff works.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900