Viewing source for recipe1010vb.aspx
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>
<%@ Page Debug="True" %>
<script runat="server" language="VB">
Sub Page_Load(sender As Object, e As EventArgs)
Dim connectionString as String = "Data Source=myServer;Initial Catalog=myCatalog;User Id=user;Password=pass"
Dim objConnection as New SqlConnection(connectionString)
Dim commandText as String = "SELECT Image FROM imageTable"
Dim objCommand as New SqlCommand(commandText, objConnection)
Dim objReader as SqlDataReader = Nothing
Try
objConnection.Open()
objReader = objCommand.ExecuteReader()
If objReader.Read() Then
Response.ContentType = "image/jpeg"
Response.BinaryWrite( CType(objReader("Image"), Byte()) )
End If
Catch exc as Exception
Response.Write(exc.Message)
Response.Write("<br>This page would display an image if its connection string were set up.")
Finally
If Not objConnection Is Nothing Then
If objConnection.State = ConnectionState.Open Then
objConnection.Close()
End If
End If
If Not objReader Is Nothing Then
objReader.Close()
End If
End Try
End Sub
</script>