<%@ 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
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="myMessage" runat="server"/>
</body>
</html>
|