Solved

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

Posted on 2014-07-23
2
281 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:murbro
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:murbro
ID: 40218005
Thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now