?
Solved

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

Posted on 2014-07-23
2
Medium Priority
?
304 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

719 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