Solved

Excel VB.net Add-in Copy Image straight to Excel from SQL

Posted on 2014-07-23
2
300 Views
Last Modified: 2014-07-24
Hi

  In my Excel VB.net add-in I am using the following code to retrieve an image from a SQL database
  and  copy it to to a picture box on a form. How do I alter the code to copy it direct to Excel?

  Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
        Dim cn As SqlConnection

        cn = New SqlConnection
        cn.ConnectionString = My.Settings.CS

        Dim cmd As New System.Data.SqlClient.SqlCommand("Select Photo from Information where Name='b'")
        cmd.Connection = cn
        cmd.CommandType = CommandType.Text

        cn.Open()

        Dim ImgStream As New IO.MemoryStream(CType(cmd.ExecuteScalar, Byte()))

        PictureBox1.Image = System.Drawing.Image.FromStream(ImgStream)

        ImgStream.Dispose()

        cmd.Connection.Close()
    End Sub
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 40216335
You can use the

Worksheet.Shapes.AddPicture

method but it takes file path so you would need to save the file to disk first (in a temp location)

http://vb.net-informations.com/excel-2007/vb.net_excel_2007_insert_picture.htm
0
 

Author Closing Comment

by:Murray Brown
ID: 40218005
Thanks
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question