Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hey Guys,

I have saved my images into database like follow.

VB
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim cmd As New SqlCommand("INSERT INTO Info VALUES(@name,@photo)", con)
        cmd.Parameters.AddWithValue("@name", TextBox1.Text)
        Dim ms As New MemoryStream()
        PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)
        Dim data As Byte() = ms.GetBuffer()
        Dim p As New SqlParameter("@photo", SqlDbType.Image)
        p.Value = data
        cmd.Parameters.Add(p)
        cmd.ExecuteNonQuery()
        MessageBox.Show("Name & Image has been saved", "Save", MessageBoxButtons.OK)
       
    End Sub



Now, On the button click event of "btnSearch_Download", I want to search image by name and

download the image saved into database to computer hard drive by giving option to user with

"save file" Dialogue box, where user can choose where he want to save a image file.

Basic code i have used is

VB
Private Sub btnSearch_Download_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch_Download.Click
        cmd = New SqlCommand("select photo from Info where name='" & TextBox2.Text & "'", con)
        Dim imageData As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
        'Tell me What to do here?
        End If
    End Sub
Posted

 
Share this answer
 
Comments
Amiet_Mhaske 13-Apr-14 9:24am    
Sir i have tried it.. But i dont know how to provide a facility to user so that he can download file at his desired location.
Add this: Dim bitmap As New Bitmap(stream)

PictureBox1.Image = bitmap
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900