Retrive an Image from database

G

Guest

Hi EveryBody:

I have the following code that I used in my application to retive image from
database:

Dim cnn As New SqlConnection("Data Source=localhost;Initial
Catalog=Husam;Integrated Security=True")
Dim cmd As SqlCommand
Dim sql As String
cnn.Open()
Sql = "SELECT Name,Picture FROM Pic"
cmd = New SqlCommand(sql, cnn)
Dim myReader As SqlDataReader = cmd.ExecuteReader()
While (myReader.Read())
byt = myReader.GetValue(1)
ms = New MemoryStream(byt)
End While
PictureBox1.Image = Image.FromStream(ms)
PictureBox1.ImageLocation = PictureBoxSizeMode.CenterImage
cnn.Close()

When I debug this project I got an error message that said:

Parameter is not valid and yellow line in
Pictuerbox1.image=image.fromstream(ms)

any help in this issue or any direction about how to retrive image from
database and disply it will be appreciated

regard's

Husam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top