如何在vb.net中从数据库中检索二值图像并在网格视图中插入图像
如何使用vb.net从数据库检索二进制图像并将图像插入GridView 这是我的数据库如何在vb.net中从数据库中检索二值图像并在网格视图中插入图像,vb.net,image,gridview,binary,Vb.net,Image,Gridview,Binary,如何使用vb.net从数据库检索二进制图像并将图像插入GridView 这是我的数据库 image(id为整数,img为varbinary(max))当您澄清所指的gridview类型时,下面介绍如何将数据插入数据库: Using c As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString) c.Open() Dim command = New S
image(id为整数,img为varbinary(max))当您澄清所指的gridview类型时,下面介绍如何将数据插入数据库:
Using c As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
c.Open()
Dim command = New SqlCommand("INSERT INTO yourtable(image) values (@image)", c)
' this is specific to the FileUploadControl but the idea is to get the
'image in a byte array; however you do it, it doesn't matter
Dim buffer(FileUpload1.PostedFile.ContentLength) As Byte
FileUpload1.PostedFile.InputStream.Read(buffer, 0, buffer.Length)
command.Parameters.AddWithValue("@image", buffer)
command.ExecuteNonQuery()
End Using
假设您谈论的是ASP.NET应用程序,您可以按如下方式将数据绑定到gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<!--Trick to encode the bytes as a BASE64 string-->
<img width="100px" height="100px" src='data:image/png;base64,<%#System.Convert.ToBase64String(Eval("image"))%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=Your_ConnectionString_GoesHere"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [id], [image] FROM [your_table_name_goes_here]">
</asp:SqlDataSource>
' />
你在说什么类型的gridview?asp.net的gridview,Winform的gridview?什么