Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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..
 
 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 Smile | :)
Posted 21-Jan-13 20:17pm
Comments
Sergey Alexandrovich Kryukov at 22-Jan-13 1:34am
   
Why, why PictureBox?!
—SA
Nikhil@123 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

   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[^]
  Permalink  
Comments
Nikhil@123 at 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 at 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".
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 85
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100