|
-
Aug 7th, 2009, 12:18 PM
#1
Thread Starter
Hyperactive Member
[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?
"Only two things are infinite; the universe and human stupidity, and I'm not sure about the former."
Albert Einstein
-
Aug 7th, 2009, 12:30 PM
#2
Re: Improve reading binary from SQL server 2008
Code:
Dim s As New IO.MemoryStream(byteTemp)
PictureBox1.Image = Image.FromStream(s)
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Aug 7th, 2009, 12:34 PM
#3
Thread Starter
Hyperactive Member
Re: Improve reading binary from SQL server 2008
Thanks, it's what I was looking for ;-)
"Only two things are infinite; the universe and human stupidity, and I'm not sure about the former."
Albert Einstein
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|