下面是一个拷贝图像到SQL Server的pubs数据库的例子, 表名pub_info, 字段名logo,图像文件名picture.bmp,保存到pub_id='0736'记录 
sp_textcopy @srvn
ame = 'ServerName', 
            @login = 'Login', 
            @password = 'Password', 
            @dbname = 'pubs', 
            @tbname = 'pub_info', 
            @colname = 'logo', 
            @filename = 'c:\picture.bmp', 
            @whereclause = " WHERE pub_id='0736' ", 
            @direction = 'I'

解决方案 »

  1.   

    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim stm As ADODB.StreamPrivate Sub SavePictureToDB(cn As ADODB.Connection)
    On Error GoTo EH
        Set stm = New ADODB.Stream
        rs.Open "select ImagePath,ImageValue from tbl_Image", cn, adOpenKeyset, adLockOptimistic
        CommonDialog1.ShowOpen
        Text1.Text = CommonDialog1.FileName
        
        With stm
             .Type = adTypeBinary
             .Open
             .LoadFromFile CommonDialog1.FileName
        End With
        With rs
             .AddNew
             .Fields("ImagePath") = Text1.Text
             .Fields("ImageValue") = stm.Read
             .Update
        End With
        rs.Close
        Set rs = Nothing
    Exit Sub
    EH: MsgBox Err.Description, vbInformation, "Error"
    End Sub
    Private Sub LoadPictureFromDB(cn As ADODB.Connection)
    On Error GoTo EH
        Dim strTemp As String
        Set stm = New ADODB.Stream
        strTemp = "c:\temp.tmp" '临时文件,用来保存读出的图片
        rs.Open "select ImagePath,ImageValue  from tbl_image", cn, , , adCmdText
        With stm
            .Type = adTypeBinary
            .Open
            .Write rs("ImageValue")
            .SaveToFile strTemp, adSaveCreateOverWrite
            .Close
        End With
        Image1.Picture = LoadPicture(strTemp)
        Set stm = Nothing
        rs.Close
        Set rs = Nothing
    Exit Sub
    EH: MsgBox Err.Description, vbInformation, "Error"
    End Sub
      

  2.   

    但ADODB.stream 好像没有定义哦
      

  3.   

    可以了
    我那个adodb的lib太旧了