net+oracle存贮图片

本文介绍了一种使用Visual Basic实现的方法,该方法能够将图片转换为字节信息,并将其保存到Oracle数据库中。具体步骤包括从PictureBox获取图片,将其转换为BMP格式的字节数组,然后使用OracleDataAdapter和OracleCommand更新数据库中的照片。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  temp = xclsywcl.SavePhoto2(txtsfzhm.Text, Photosbinary())
                    If temp = "" Then
                        MsgBox("新增成功")
                        txtsfzhm.Focus()
                    Else
                        MsgBox("更新照片时发生错误,错误原因:" & temp)
                    End If

 

 

 

 '将图片转化为字节信息
    Private Function Photosbinary() As Byte()
       Try
            Dim image As New Bitmap(PictureBox1.Image)
            Dim stream As New MemoryStream
            image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)
            Return stream.ToArray()

        Catch ex As Exception
            Return Nothing
        End Try

     End Function

 

 

        Public Function SavePhoto2(ByVal data_id As String, ByVal p_Blob As Byte()) As String
            Dim cn As OracleConnection = New OracleConnection(GetConn2)  'oracle数据库
            Try
                cn.Open()
                Dim photoadapter As OracleDataAdapter
                photoadapter = New OracleDataAdapter("SELECT *  FROM drv_photo WHERE  sfzmhm ='" + data_id + "'", cn)
                Dim photoDataSet As New DataSet("drv_photo")
                photoadapter.Fill(photoDataSet, "drv_photo")
                Dim updatesql As String = "UPDATE drv_photo SET zp=:vPHOTO  WHERE sfzmhm='" + data_id + "'"
                Dim updatecmd As New OracleCommand(updatesql, cn)
                photoadapter.UpdateCommand = updatecmd
                photoadapter.UpdateCommand.Parameters.Add(":vPHOTO", OracleType.Blob, p_Blob.Length, "ZP")
                photoadapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
                photoadapter.FillSchema(photoDataSet, SchemaType.Source, "drv_photo")
                photoadapter.Fill(photoDataSet, "drv_photo")
                Dim phototable As DataTable                         'table
                Dim photoRow As DataRow                                'datarow
                phototable = photoDataSet.Tables("drv_photo")
                photoRow = phototable.Rows(0)
                photoRow.BeginEdit()
                photoRow("zp") = p_Blob
                photoRow.EndEdit()
                photoadapter.Update(photoDataSet, "drv_photo")
                Return ""
            Catch e As Exception
                Return e.ToString
            Finally
                cn.Close()
            End Try
        End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值