2011-09-03 3 views

답변

0

당신이 참조하고있는 gridview의 유형을 명확히하는 동안 내 DB 인 데이터베이스에 데이터를 삽입하는 방법 다음과 같이

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> 
관련 문제