Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks