Hello,
I have this code, to read image (saved as varbinary(max) in database):But it isn't very convenient code. It reads bytes from table, save them to file, and finally open file as image.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
How can I read it directly to image, without saving as file?




Reply With Quote