Solved

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

Posted on 2014-07-23
2
292 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…

821 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