L
LB
Hello everybody,
I'm trying to display into a system.Web.UI.WebControls.Image a picture
coming from the DB.
I used the code below, and after specifying my image1.url property, the
image is displayed.
But now, I have still the image stored in my "DestFilePath " directory.
Is there a way to directly read the blob, and assign it to my
system.Web.UI.WebControls.Image without writing the file itself to the disk
?
Thank you so much in advance
LB
Public Sub GetBlobInfo(DestFilePath As String)
Try
Dim PictureCol As Integer = 0 ' the column # of the BLOB field
Dim cn As New SqlConnection("server=localhost;integrated
security=yes;database=SomeDB")
Dim cmd As New SqlCommand("SELECT Picture FROM mytable WHERE
somecondition='Test'", cn)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue)) As
[Byte]
dr.GetBytes(PictureCol, 0, b, 0, b.Length)
dr.Close()
cn.Close()
Dim fs As New System.IO.FileStream(DestFilePath,
System.IO.FileMode.Create, System.IO.FileAccess.Write)
fs.Write(b, 0, b.Length)
fs.Close()
MessageBox.Show("Image written to file successfully")
Catch ex As SqlException
MessageBox.Show(ex.Message)
End Try
End Sub
I'm trying to display into a system.Web.UI.WebControls.Image a picture
coming from the DB.
I used the code below, and after specifying my image1.url property, the
image is displayed.
But now, I have still the image stored in my "DestFilePath " directory.
Is there a way to directly read the blob, and assign it to my
system.Web.UI.WebControls.Image without writing the file itself to the disk
?
Thank you so much in advance
LB
Public Sub GetBlobInfo(DestFilePath As String)
Try
Dim PictureCol As Integer = 0 ' the column # of the BLOB field
Dim cn As New SqlConnection("server=localhost;integrated
security=yes;database=SomeDB")
Dim cmd As New SqlCommand("SELECT Picture FROM mytable WHERE
somecondition='Test'", cn)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue)) As
[Byte]
dr.GetBytes(PictureCol, 0, b, 0, b.Length)
dr.Close()
cn.Close()
Dim fs As New System.IO.FileStream(DestFilePath,
System.IO.FileMode.Create, System.IO.FileAccess.Write)
fs.Write(b, 0, b.Length)
fs.Close()
MessageBox.Show("Image written to file successfully")
Catch ex As SqlException
MessageBox.Show(ex.Message)
End Try
End Sub