In my previous post I have discuss about how to store image into sql server database using vb.net.
It is time to fetch image from sql server database and
display into picture box. Here is the snapshot of vb.net code.
First of all we have to imports these namespace in our class.
Imports System.IO
Imports
System.IO.Stream
Public Function getImagefromByte(ByVal
data As Byte())
As Image
Dim ms As MemoryStream = New
MemoryStream()
Dim img
As Image
Try
ms.Write(data, 0,
data.GetUpperBound(0))
img = Image.FromStream(ms)
Catch
ex As Exception
img = My.Resources.noimage
Finally
'ms.Close()
'ms =
Nothing
End Try
getImagefromByte = img
End Function
Here is code that show how to call this function
and display image into picture box. ds is object of DataSet class and DataAdaptor
is used fill that dataset, ”photo” field type in sql database is image.
pic is PictureBox control.
Dim data() As
Byte
data = CType(ds.Tables(0).Rows(0)("photo"), Byte())
pic.Image = getImagefromByte(data)
this will fetch picture from sql database and display into picture box.
my search ends here for display image from sql server database to picture box.solved my problem.
ReplyDeleteThanks
Rakesh
Hello, I want to fetch the picture from database, which I do kind of like you explain here, but then I don't have a picturebox, I only have a RichTextBox with html email Body.
ReplyDeleteMy picture is in memorystream from database and i want to replace the embedded pictures in the html with my new downloaded picture.
Can you help?