Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在vb.net中从数据库中检索二值图像并在网格视图中插入图像_Vb.net_Image_Gridview_Binary - Fatal编程技术网

如何在vb.net中从数据库中检索二值图像并在网格视图中插入图像

如何在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

如何使用vb.net从数据库检索二进制图像并将图像插入GridView

这是我的数据库


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?什么