Click here to Skip to main content
15,909,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one table with name Student have two image fields (Photo) and (signature)
I have datasource, add table to a new dataset... and Drag all field in detail view into a new form...
I can easily navigate records, edit records and save records by using navigation bar....
BUT unable to update photo... please help....

How to update image please help....
Posted

1 solution

here i m giving code in vb.net
1. First make property of that fields like
VB
Public Property StudentPhoto() As Object
        Get
            Return _StudentPhoto
        End Get
        Set(ByVal value As Object)
            If IsDBNull(value) = True Then
                _StudentPhoto = value
                _PhotoPath = ""
            Else
                If value.GetType.Name = "String" Then
                    _PhotoPath = System.Web.HttpContext.Current.ApplicationInstance.Server.MapPath(value.ToString)
                    Dim st As New System.IO.FileStream(_PhotoPath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
                    Dim mbr As System.IO.BinaryReader = New IO.BinaryReader(st)
                    Dim buffer(st.Length) As Byte
                    mbr.Read(buffer, 0, CInt(st.Length))
                    _StudentPhoto = buffer
                Else
                    _StudentPhoto = value
                    Dim arrPhoto() As Byte = CType(_StudentPhoto, Byte())
                    _StudentPhoto = arrPhoto
                    Dim stPhote As New IO.MemoryStream(arrPhoto)
                    _PhotoPath = "/PhotoUpload/" & _PhotoID & ".jpeg"
                    Try
                        Dim imgPhoto As Image = Image.FromStream(stPhote)
                        imgPhoto.Save(System.Web.HttpContext.Current.ApplicationInstance.Server.MapPath(_PhotoPath), Imaging.ImageFormat.Jpeg)
                        _PhotoPath = "~" & _PhotoPath
                    Catch ex As Exception
                        _StudentPhoto = DBNull.Value
                        _PhotoPath = ""
                    End Try
                End If
            End If
        End Set
    End Property

2. and on UI set valuetoobject means set value to object
like
VB
Dim Recordid As Integer = objStudentConvo.GetStudentConvoRecordID(Session("UserMailID"))
      If upimgphoto.ImageUrl = "~/PhotoUpload/New/Blank.jpg" Then
          objStudentPhotocls.StudentPhoto = DBNull.Value
      Else
          objStudentPhotocls.StudentPhoto = upimgphoto.ImageUrl
      End If
      objStudentPhotocls.ConvoID = objStudentConvo.ConvoID
      objStudentPhotocls.RecordID = Recordid

3. Update this object by sending this object to stored procedure
 
Share this answer
 
v2
Comments
Member 10279246 1-Jan-14 9:12am    
I am not much familiar with this.... is there any soft method...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900