[求助]用Datalist读取Access中的图片-->bygg转移
我想用datalist读取Images.mdb中的图片。其中Images.mdb包含两个字节:id(自动编号),img(OLE对象)。我给datalist中的img对象的src设置为"src="Handler.ashx?id=<%# Eval("id") %>"
下面是我在handler.ashx中的代码
------------------------------------------------------------------------------------------------------------------------------------
<%@ WebHandler Language="VB" Class="Handler" %>
Public Class Handler
Implements IHttpHandler
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
' 设置响应设置
context.Response.ContentType = "image/gif"
context.Response.Cache.SetCacheability(HttpCacheability.Public)
context.Response.BufferOutput = False
' 设置 ID 参数
Dim id As Int32 = 1
Dim stream As IO.Stream = Nothing
Dim conn As New Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("Images").ConnectionString)
Dim command As Data.OleDb.OleDbCommand
Dim reader As Data.OleDb.OleDbDataReader
Dim buffersize As Integer = (1024 * 768)
Dim buffer() As Byte = New Byte((buffersize) - 1) {}
Dim count As Integer
If ((Not (context.Request.QueryString("id")) Is Nothing) _
AndAlso (context.Request.QueryString("id") <> "")) Then
id = [Convert].ToInt32(context.Request.QueryString("id"))
End If
conn.Open()
command = New Data.OleDb.OleDbCommand("SELECT * FROM Table1 WHERE id = " & id, conn)
reader = command.ExecuteReader()
reader.Read()
stream = New IO.MemoryStream(CType(reader("img"), Byte()))
count = stream.Read(buffer, 0, buffersize)
Do While (count > 0)
context.Response.OutputStream.Write(buffer, 0, count)
count = stream.Read(buffer, 0, buffersize)
Loop
End Sub
End Class
----------------------------------------------------------------------------------------------------------------------------
用断点监视,发现stream中已经有了数据,但最终还是无法在datalist中正常显示图片。我已经换了好几种办法了,可是都不能正常显示
还请各路大仙帮我想想找找看我的代码中有什么问题。
或者能告诉我新的办法。谢谢了