问题:
    如果原更新页面有照片显示,再通过input更新照片就更新不了,更新为空能成功,
    如果原更新页面没有照片显示(就是个人信息没有上传照片),通过input更新照片就能更新成功。
    我的照片是传到数据库里的。

解决方案 »

  1.   

    <script runat="server">


    public sub abc (sender As Object, e As EventArgs)

    Dim intImageSize As Int64
    Dim strImageType As String
    Dim ImageStream As Stream
     
    ' 获得图片的大小
    intImageSize = PersonImage2.PostedFile.ContentLength
    ' 获得图片类型
    strImageType = PersonImage2.PostedFile.ContentType
    '读取图片
    ImageStream = PersonImage2.PostedFile.InputStream
    Dim ImageContent(intImageSize) As Byte
    Dim intStatus As Integer
    intStatus = ImageStream.Read(ImageContent, 0, intImageSize)
    ' 创建Connection和Command对象.
    Dim strCnn As String = "server=server;database=resource;uid=sa;Pwd="
    Dim myConnection As New SqlConnection(strCnn)
    Dim myCommand As New SqlCommand("sp_person_upim",myConnection)
    ' 使用存储过程
    myCommand.CommandType = CommandType.StoredProcedure
    ' 向存储过程添加姓名
    dim prmid as new sqlparameter("@personid",sqldbtype.int,4)
    prmid.value=Request.QueryString("personid")
    mycommand.parameters.add(prmid)
    '向存储过程添加照片
    Dim prmPersonImage As New SqlParameter("@PersonImage", SqlDbType.Image)
    prmPersonImage.Value = ImageContent
    myCommand.Parameters.Add(prmPersonImage)
    '向存储过程添加图片类型
    Dim prmPersonImageType As New SqlParameter("@PersonImageType", SqlDbType.VarChar, 50)
    prmPersonImageType.Value = strImageType
    myCommand.Parameters.Add(prmPersonImageType)

    myConnection.Open()

    Try
    myCommand.ExecuteNonQuery()
    Response.Write("<script language='javascript'>alert('更新成功!');</" & "script>")

    Catch SQLexc As SqlException
    Response.Write("<script language='javascript'>alert('更新失败!');</" & "script>") 
    End Try
    myConnection.Close()
    Response.Write("<script language='javascript'>window.location = window.location;</" & "script>")
    end sub

    sub page_load()
    personimage.imageurl="showimage.aspx?personid=" & Request.QueryString("personid")

    end sub
    </script>