从Microsoft SQL Server的PUB数据库读取图片并显示它
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Sub Page_load(Sender as Object, E as EventArgs)
dim stream as new MemoryStream
dim connection as SqlConnection
connection=new SqlConnection("server=localhost;database=pubs;uid=sa;pwd=")
try
connection.Open()
dim command as SqlCommand
command = new SqlCommand ("select logo from pub_info where pub_id='0736'", connection)
dim image as byte()
image = command.ExecuteScalar ()
stream.Write (image, 0, image.Length)
dim imgbitmap as bitmap
imgbitmap = new Bitmap (stream)
Response.ContentType = "image/gif"
imgbitmap.Save (Response.OutputStream, ImageFormat.Gif)
Finally
connection.Close()
stream.Clse()
End Try
End Sub
</script>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Sub Page_load(Sender as Object, E as EventArgs)
dim stream as new MemoryStream
dim connection as SqlConnection
connection=new SqlConnection("server=localhost;database=pubs;uid=sa;pwd=")
try
connection.Open()
dim command as SqlCommand
command = new SqlCommand ("select logo from pub_info where pub_id='0736'", connection)
dim image as byte()
image = command.ExecuteScalar ()
stream.Write (image, 0, image.Length)
dim imgbitmap as bitmap
imgbitmap = new Bitmap (stream)
Response.ContentType = "image/gif"
imgbitmap.Save (Response.OutputStream, ImageFormat.Gif)
Finally
connection.Close()
stream.Clse()
End Try
End Sub
</script>