1

我希望使用 ASP.Net 在 Gridview 中显示我的 MS-Access 数据库 OLE 对象。这是我到目前为止所拥有的:

<%@ WebHandler Language="VB" Class="Handler3" %>  
           Imports System  
           Imports System.Web  
           Imports System.Data.OleDb  

       Public Class Handler3 : Implements IHttpHandler

        Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        context.Response.ContentType = "image/jpeg"
        Dim id As Integer = Convert.ToInt32(context.Request.QueryString("Imageid"))
        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & "PivotDb.accdb" & ";")
        con.Open()
        Dim cmd As OleDbCommand = New OleDbCommand("select Img from imgupload where ID=" & id & "", con)
        Dim reader As OleDbDataReader = cmd.ExecuteReader
        reader.Read()
        Dim image As Byte() = DirectCast(reader(1), Byte())
        context.Response.BinaryWrite(image)
        reader.Close()

    End Sub

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class
4

0 回答 0