现在有一个这样的问题,我要写一个存储过程接受其他系统传过来的图片然后存到我本身的数据库中,参数如下:
     emp_id 工号,picture 图片,以二进制格式发送过来.
    现要写存储过程来接受图片,一个一个接受,也多个一起接受然后存到sql server数据库表中.不知道如何写请各位大师帮忙.谢谢

解决方案 »

  1.   

    存取图片最好直接在客户段处理,参考http://blog.csdn.net/jinjazz/archive/2007/11/19/1892797.aspx
      

  2.   

    这个是取出的,保存的用参数传byte[]进去就可以了。
      

  3.   

    单个的话:create proc p
    @emp_id int,
    @picture image然后直接插就是了。因为@picture如你所说,本身就是二进制格式。而我个的话,就不清楚你怎么传了。
      

  4.   

    传过来我接收,往表里面insert, 还要把二进制图片转化为image类型的图片.
      

  5.   

    这里这么多大虾在帮你。我都怕怕啊。其实,网上有许多例子的。有也代码。 
    贴一下我写的代码:http://blog.csdn.net/linjimu/archive/2008/08/01/2754893.aspx 
    【SQL SERVER数据库的Image字段来存储图片。对图片读取采用二进制和FileStream文件流。 
    其中还要用到数据库的存储过程来插入和读取图片信息记录的内容。数据库中的图片可以另存在硬盘上。支持常见的几个格式】 
    程序界面和数据库下载:http://download.csdn.net/source/566140
      

  6.   


    Function AddAndUpdateImg() As Boolean 
            Dim fs As FileStream 
            Try 
                SqlConn = New SqlConnection(SQLClass.ConnectString) 
                SqlComm = New SqlCommand 
                SqlComm.Connection = SqlConn 
                SqlComm.CommandType = CommandType.StoredProcedure 
                SqlComm.CommandText = "AddAndUpdateImg" 
                pr = New SqlParameter("@ImgID", SqlDbType.Int) 
                pr.Value = CInt(Me.TxtBoxImgID.Text) 
                SqlComm.Parameters.Add(pr) 
                pr = New SqlParameter("@ImgName", SqlDbType.NVarChar, 255) 
                pr.Value = Me.TxtBoxImgName.Text 
                SqlComm.Parameters.Add(pr) 
                pr = New SqlParameter("@ImgDes", SqlDbType.NVarChar, 1000) 
                If Me.TxtBoxImgDes.Text > "" Then 
                    pr.Value = Me.TxtBoxImgDes.Text 
                Else 
                    pr.Value = "" 
                End If 
                SqlComm.Parameters.Add(pr) 
                pr = New SqlParameter("@ImgExtName", SqlDbType.NVarChar, 10) 
                If Me.TxtBoxImgExtName.Text > "" Then 
                    pr.Value = Me.TxtBoxImgExtName.Text 
                Else 
                    pr.Value = "" 
                End If 
                SqlComm.Parameters.Add(pr) 
                pr = New SqlParameter("@ImgTypeID", SqlDbType.Int) 
                If Me.TxtBoxImgTypeID.Text > "" Then pr.Value = CInt(Me.TxtBoxImgTypeID.Text) 
                SqlComm.Parameters.Add(pr) 
                pr = New SqlParameter("@UpdateTime", SqlDbType.SmallDateTime) 
                pr.Value = Me.TImgUpdateTime.Value 
                SqlComm.Parameters.Add(pr) 
                pr = New SqlParameter("@ImgBinary", SqlDbType.Image) 
                If ImgPath > "" Then 
                    fs = New FileStream(ImgPath, FileMode.Open) 
                    Dim bt(fs.Length) As Byte 
                    fs.Read(bt, 0, fs.Length) 
                    pr.Value = bt 
                Else 
                    If Me.ImgBox.Image IsNot Nothing Then 
                        Me.ImgBox.Image.Save(fs, Me.ImgBox.Image.RawFormat) 
                        Dim bt(fs.Length) As Byte 
                        fs.Read(bt, 0, fs.Length) 
                        pr.Value = bt 
                    End If 
                End If 
                SqlComm.Parameters.Add(pr) 
                SqlConn.Open() 
                SqlComm.ExecuteNonQuery() 
                Try 
                    fs.Close() 
                Catch ex As Exception 
                End Try 
                SqlConn.Close() 
                SqlConn = Nothing 
                Return True 
            Catch ex As SqlException 
                Dim errItem As SqlError 
                Dim errString As String = "" 
                For Each errItem In ex.Errors 
                    errString += ex.Message + " " 
                Next 
                MsgBox("SQL错误.详细内容:" & errString) 
                Return False 
            Catch myException As Exception 
                MsgBox("异常描述:" + myException.ToString()) 
                Return False 
            End Try 
        End Function 
      

  7.   

    我写了个存储过程,各位高手看下能直接接受二进制格式的图片吗,@image是二进制格式的,能直接这么存和更新吗.
    create procedure insert_emp_picture
    @emp_id char(5),
    @image  image
    as
    begin transaction
    if @emp_id in(select emp_id from emp_picture)
    begin
       update emp_picture set image=@image where emp_id=@emp_id
       if @@error<>0 or @@rowcount=0
       begin
       goto error
       end
    end
    else
    begin
      insert into emp_picture
        select @emp_id,@image
        if @@error<>0 or @@rowcount=0
       begin
       goto error
       end
    end
    commit transaction
     return 0
    error:
      rollback transaction
     return 1
    go