Writing binary content in ASP.NET : Binary « ADO.net Database « ASP.Net






Writing binary content in ASP.NET

<%@ Page Language="vb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>
<html>
   <head>
      <title>Writing binary content in ASP.NET</title>
      <script runat="server">
         Sub Page_Load()
            Dim ConnStr As String
            'change the following string to your settings
            ConnStr = "Data Source=(local)\NetSDK;"
            ConnStr &= "database=pubs;integrated security=true"
            Dim mySqlConn As New SqlConnection(ConnStr)
            mySqlConn.Open
            Dim SQL As String = "SELECT logo FROM pub_info WHERE pub_id = '0736'"
            Dim mySqlCmd as New SqlCommand(SQL, mySqlConn)
            mySqlCmd.CommandType = CommandType.Text
            Dim Reader As SqlDataReader
            Reader = mySqlCmd.ExecuteReader()
            Dim ImageBytes() As Byte
            While Reader.Read()
               ImageBytes = Reader.Item(0)
            End While
            Response.ContentType = "image/bmp"
            Response.BinaryWrite(ImageBytes)
            Response.End()
            Reader.Close()
            mySqlConn.Close()
         End Sub
      </script>
   </head>
<body>
   <asp:label id="Message" runat="server"/>
</body>
</html>
           
       








Related examples in the same category