.net + SQL语句和存贮过程插入图片

本文介绍了使用存储过程和函数来处理图片数据的插入操作。通过具体的VB.NET代码示例,展示了如何创建存储过程并调用它来将图片数据保存到数据库中。此外,还提供了一个函数用于直接插入图片数据。

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

   Public Function test_add(ByVal cxybh As String, ByVal zp As Byte()) As Integer
            Dim strsql As String
            Try
             

                Dim arParms() As SqlParameter = New SqlParameter(1) {}
                arParms(0) = New SqlParameter("@cxybh", System.Data.SqlDbType.NVarChar, 50)
                arParms(0).Value = cxybh
                arParms(1) = New SqlParameter("@cpic", System.Data.SqlDbType.Image)
                arParms(1).Value = zp
                Try
                    SqlHelper.ExecuteNonQuery(GetConn, System.Data.CommandType.Text, "insert into ec_pic(cxybh,cpic) values(@cxybh,@cpic)", arParms)

                Catch ex As Exception

                End Try

                Return 0
            Catch ex As Exception
            Finally

            End Try
        End Function

 

 

 

利用存贮过程调用

 Public Function savepicbyxybh(ByVal cxybh As String, ByVal cpic As Byte(), ByVal cpicsmall As Byte(), ByVal cpic2 As Byte()) As Boolean
            Try

                Dim arParms() As SqlParameter = New SqlParameter(3) {}
                arParms(0) = New SqlParameter("@pcxybh", System.Data.SqlDbType.NVarChar, 50)
                arParms(0).Value = cxybh
                arParms(1) = New SqlParameter("@pcpic", System.Data.SqlDbType.Image)
                arParms(1).Value = cpic
                arParms(2) = New SqlParameter("@pcpicsmall", System.Data.SqlDbType.Image)
                arParms(2).Value = cpicsmall
                arParms(3) = New SqlParameter("@pcpic2", System.Data.SqlDbType.Image)
                arParms(3).Value = cpic2
                Try
                    SqlHelper.ExecuteNonQuery(GetConn, System.Data.CommandType.StoredProcedure, "addcpic", arParms)
                    Return True
                Catch ex As Exception
                    Return False
                End Try

            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End Function

 

 

存贮过程如下:

 

CREATE     PROCEDURE addcpic
@pcxybh nvarchar(255),
@pcpic image,
@pcpic2 image,
@pcpicsmall image
As
Begin
insert into ec_pic(cxybh,cpic,cpic2,cpicsmall) values(@pcxybh,@pcpic,@pcpic2,@pcpicsmall)
Select @@RowCount
End

 


GO

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值