我想在一个MySQL数据库中检索多个图像,以便在加载表单后将其添加到图像列表集合中。
我在表单加载事件中尝试过的事情:
cn.Open()
Using cmd = New MySqlCommand("SELECT * FROM tbl_products", cn)
da.SelectCommand = cmd
Dim dt_images As New DataTable
da.Fill(dt_images)
For Each dr As DataRow In dt_images.Rows
Dim img_buffer = CType(dr("IMAGE"), Byte())
Dim img_stream As New MemoryStream(img_buffer, True)
img_stream.Write(img_buffer, 0, img_buffer.Length)
imglist.Images.Add(dr("image").ToString(), New Bitmap(img_stream))
img_stream.Close()
Next
End Using
cn.Close()
Using connection As New MySqlConnection("connection string here"),
command As New MySqlCommand("SELECT image FROM tbl_products", connection)
connection.Open()
Using reader = command.ExecuteReader()
While reader.Read()
Using stream As New MemoryStream(DirectCast(reader("image"), Byte()))
imglist.Images.Add(Image.FromStream(stream))
End Using
End While
End Using
End Using