在Sql表中更新记录 [英] Update Record in Sql Table

查看:60
本文介绍了在Sql表中更新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Student的表有两个图像字段(Photo)和(签名)

我有数据源,将表添加到新数据集...并将详细视图中的所有字段拖入一个新表格...

我可以使用导航栏轻松导航记录,编辑记录和保存记录....

但无法更新照片...请帮助....



如何更新图像请帮助....

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....

推荐答案

这里我在vb.net中给出代码

1.首先使该字段的属性如

here i m giving code in vb.net
1. First make property of that fields like
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.并在UI上设置valuetoobject意味着设置值为object

like


2. and on UI set valuetoobject means set value to object
like

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.通过将此对象发送到存储过程来更新此对象


3. Update this object by sending this object to stored procedure


这篇关于在Sql表中更新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆