如何在vb.net中从mysql到imagelist检索多个图像
我想从MySQL数据库中检索多个图像,以便在加载表单后添加到图像列表集合中 我在表单加载事件中尝试的内容:如何在vb.net中从mysql到imagelist检索多个图像,vb.net,vb.net-2010,Vb.net,Vb.net 2010,我想从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_ima
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()
将连接用作新的MySqlConnection(“此处的连接字符串”),
命令作为新的MySqlCommand(“从tbl_产品中选择图像”,连接)
connection.Open()
使用reader=command.ExecuteReader()
而reader.Read()
使用流作为新的内存流(DirectCast(reader(“image”),Byte())
imglist.Images.Add(Image.FromStream(stream))
终端使用
结束时
终端使用
终端使用
将连接用作新的MySqlConnection(“此处的连接字符串”),
命令作为新的MySqlCommand(“从tbl_产品中选择图像”,连接)
connection.Open()
使用reader=command.ExecuteReader()
而reader.Read()
使用流作为新的内存流(DirectCast(reader(“image”),Byte())
imglist.Images.Add(Image.FromStream(stream))
终端使用
结束时
终端使用
终端使用
首先,如代码所示,存储图像的列命名为(IMAGE)
它必须具有OLE对象的数据类型
第二,在这方面:
imglist.Images.Add(dr("image").ToString(), New Bitmap(img_stream))
dr(“图像”)是图像键字符串,不包含图像列
所以我建议您在数据库中创建一个名为example(RankID)的新列
具有(自动编号)数据类型,然后将此行更改为:
imglist.Images.Add(dr("RankID").ToString(), New Bitmap(img_stream))
最后,您只是将图像添加到imagelist,需要一个listview来显示它。
创建新的listview(listview1),然后在for each循环中添加以下行:
Dim isvparent As New ListViewItem
isvparent.ImageKey = myrow("RankID")
ListView1.Items.Add(isvparent)
首先,如代码所示,存储图像的列被命名为(IMAGE) 它必须具有OLE对象的数据类型 第二,在这方面:
imglist.Images.Add(dr("image").ToString(), New Bitmap(img_stream))
dr(“图像”)是图像键字符串,不包含图像列
所以我建议您在数据库中创建一个名为example(RankID)的新列
具有(自动编号)数据类型,然后将此行更改为:
imglist.Images.Add(dr("RankID").ToString(), New Bitmap(img_stream))
最后,您只是将图像添加到imagelist,需要一个listview来显示它。
创建新的listview(listview1),然后在for each循环中添加以下行:
Dim isvparent As New ListViewItem
isvparent.ImageKey = myrow("RankID")
ListView1.Items.Add(isvparent)