如何从数据库显示图像,我正在使用asp.net

时间:2014-06-27 02:09:18

标签: asp.net sql-server imageurl

我在从数据库显示图像时遇到问题(我使用的是sql server 2008) 它说"无法创建类型' LeaveApplication.EmployeePhoto'。"

Employee.aspx

  <asp:Image ID="empPic" runat="server" Height="200px" ImageUrl="~/Images/pic.jpg" Width="200px" /></div>

Employee.aspx.vb

Dim ses As String     ses = Session(&#34; ses_empNum&#34;)     txtEmployeeNum.Text = ses

'empPic.ImageUrl = "../usrcontrols/EmployeePhoto.ashx?EmpNum'" & ses & "'"
empPic.ImageUrl = "../usrcontrols/EmployeePhoto.ashx?id=idkey'" & ses & "'"

EmplpyeePhoto.ashx.vb

    Imports System.Web
Imports System.Web.Services
Imports System.Data
Imports System.Data.SqlClient

Public Class PatientPhoto
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest


        Dim ID As New String(context.Request.QueryString("ID"))

        Dim sqlConn As New SqlConnection("server=192.168.6.7;uid=sa;pwd=da;database=payroll_hospital;multipleactiveresultsets=true")
        sqlConn.Open()

        ID = Replace(ID, "^", "'")
        Dim sqlComm As New SqlCommand("select dbImage from patient_data.dbo.tbdbImage where " & ID, sqlConn)
        'context.Response.Write)
        'Exit Sub

        'context.Session.Item("test") = "select dbImage from patient_data.dbo.tbdbImage where " & ID

        Dim dr As System.Data.SqlClient.SqlDataReader

        dr = sqlComm.ExecuteReader
        If dr.Read Then
            context.Response.BinaryWrite(dr.Item("dbImage"))
        Else
            'Response.Write("File Not Found.")
            context.Response.Write("<img src=../images/blank.jpg>")
        End If
        sqlConn.Close()



    End Sub

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

End Class

Employee.ashx

1 个答案:

答案 0 :(得分:1)

我打赌你在某个地方重命名了一个代码类,但没有更新页面后面的代码。页面后面的代码在手动更改时不知道名称是什么。

寻找修改类名的地方。

public MyChangedClass:Page{} 

<%@ CodeBehind="MyChangedClass.aspx.cs" Class="MyOldClassName" %>