[RESOLVED] Improve reading binary from SQL server 2008
Hello,
I have this code, to read image (saved as varbinary(max) in database):
Code:
Private Sub ReadImage()
Dim connection As New SqlConnection(strConnectionString)
Dim command As New SqlCommand("SELECT [Image] FROM z1 WHERE x=1 AND y=1", connection)
connection.Open()
Dim byteTmp() As Byte = command.ExecuteScalar
connection.Close()
Dim strfn As String = Convert.ToString(DateTime.Now.ToFileTime())
Dim fs As New IO.FileStream(strfn, IO.FileMode.CreateNew, IO.FileAccess.Write)
fs.Write(byteTmp, 0, byteTmp.Length)
fs.Flush()
fs.Close()
PictureBox1.Image = Image.FromFile(strfn)
End Sub
But it isn't very convenient code. It reads bytes from table, save them to file, and finally open file as image.
How can I read it directly to image, without saving as file?
Re: Improve reading binary from SQL server 2008
Code:
Dim s As New IO.MemoryStream(byteTemp)
PictureBox1.Image = Image.FromStream(s)
Re: Improve reading binary from SQL server 2008
Thanks, it's what I was looking for ;-)