如何在Gridview中显示MS-Access OLE对象?

时间:2013-06-19 10:46:44

标签: asp.net vb.net

我希望使用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

0 个答案:

没有答案