Morning all,

I have the following code that gets a jpg image from sql which works fine.
What i would now like to do is save this image as a file on my pc in a temp folder that i can use in a report. i would like to change the name of this image to the sheltercode. can this be done.

below is the code that i use to get the image from the sql table and populate into a picture box on my form.


            Using cmd As New SqlClient.SqlCommand("Select Imagedata From animalimage where sheltercode ='" & Me.lbshelter.Text & "'", conn)
                Using dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
                    Using dt As New DataTable
                        If dt.Rows.Count = 0 Then Exit Sub
                        Dim row As DataRow = dt.Rows(0)
                        Using ms As New IO.MemoryStream(CType(row("Imagedata"), Byte()))
                            Dim img As Image = Image.FromStream(ms)
                            PictureBox1.Image = img
                        End Using
                    End Using
                End Using
            End Using
        End Using
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage

Try this:

After line 18 of your code provided to us, write these LOC:
Dim bmp as System.Drawing.Bitmap = new System.Drawing.Bitmap(PictureBox1.Image)
bmp.Save("FILENAME.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

This question has already been answered. Start a new discussion instead.