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

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

被折叠的 条评论
为什么被折叠?



