Private Sub cmdNext_Click() ' 查看下一张图片
    rst.MoveNext
    ViewImage
End Sub
——————————————————————
Private Sub CmdSaveImage_Click() '把图片保存到数据库中!
    Dim strFileName As String
    With CommonDialog1
        .Filter = "JPF文件|*.jpg"
        .ShowOpen
        strFileName = .FileName
    End With
    stream1.LoadFromFile strFileName
    rst.Fields("image1").Value = stream1.Read
    rst.Update
    If Err.Number = 0 Then
        MsgBox "Save Successfully!"
    Else
        MsgBox Err.Number & ":" & Err.Description
    End If
End Sub
----------------------——————————
Private Sub CmdViewImage_Click()
    ViewImage
End Sub
--------------------------------—————
Private Sub Form_Load()
    Dim fso As Folder
    Set cnn = New ADODB.Connection
    cnn.Open strpath
    Set rst = New ADODB.Recordset
    rst.Open "Select * from SaveImage", cnn, adOpenKeyset, adLockOptimistic, adCmdText
    Set stream1 = New ADODB.Stream
    stream1.Type = adTypeBinary
    stream1.Open
End Sub
——————————————————————
Private Sub Form_Unload(Cancel As Integer)
    stream1.Close
    rst.Close
    cnn.Close
    Set stream1 = Nothing
    Set rst = Nothing
    Set cnn = Nothing
End Sub
——————————————————————
Sub ViewImage()   
        stream1.Write rst.Fields("image1").Value
        stream1.SaveToFile App.Path & "\tmp.jpg", adSaveCreateOverWrite
        Image1.Picture = LoadPicture(App.Path & "\tmp.jpg")   '这里有错!奇怪!我查看过App.Path & "\tmp.jpg"有这个文件。   
End Sub
——————————————————————
请各位朋友耐心看一下代码(可能长了一点),其功能是实现图片保存到数据库中CmdSaveImage_Click(),再接下来通过Image控件观看数据库中的图片CmdViewImage_Click,在运行过程中,我发现 CmdViewImage_Click可以保存图像到数据库中,但奇怪的是纪录数总为2条?在显示下一条纪录(图片)cmdNext_Click() 时,发现提示"无効图片",Image1.Picture = LoadPicture(App.Path & "\tmp.jpg")

解决方案 »

  1.   

    是不是Image1.Picture = LoadPicture(App.Path & "\tmp.jpg") ?
     Image1.Picture = LoadPicture(""& App.Path & "\tmp.jpg") 试试看
      

  2.   

    let me have a test!
      

  3.   

    问题越来越大了!我发现代码:
        stream1.LoadFromFile strFileName
        rst.Fields("image1").Value = stream1.Read
        rst.Update
    实际并没有保存图片(只能保存一张照片,数据库大小始终不变),但Err.number=0,奇怪!而且代码:
    Sub ViewImage()
            stream1.Write rst.Fields("image1").Value
            stream1.SaveToFile App.Path & "\tmp.jpg", adSaveCreateOverWrite
            Image1.Picture = LoadPicture("" & App.Path & "\tmp.jpg")
    End Sub
    查看了tmp.jpg大小,不过只有几个字节的大小,难道stream1.SaveToFile App.Path & "\tmp.jpg", adSaveCreateOverWrite没有把image字段中的内容保存到tmp.jpg中吗?
    请各位朋友多多发表自己的见解,有用、无用都可以!
      

  4.   

    你的代码是更新数据库中的图片,没有加记录.
    先使用这句:
    rst.AddNew
      

  5.   

    stream1.LoadFromFile strFileName
    <>rst.AddNew????
      

  6.   

    stream用完后一定要加上:stream.close,否则后面的照片存不进去。存为文件后也要close
    否则打开文件会出现只读或占用。
    -------------------------------------------
    Sub ViewImage()   
            stream1.Write rst.Fields("image1").Value
            stream1.SaveToFile App.Path & "\tmp.jpg", adSaveCreateOverWrite
            stream1.close
            Image1.Picture = LoadPicture(App.Path & "\tmp.jpg")   '这里有错!奇怪!我查看过App.Path & "\tmp.jpg"有这个文件。   
    End Sub
    -----------------------------------------------
      stream1.LoadFromFile strFileName
        rst.Fields("image1").Value = stream1.Read
        rst.Update
        If Err.Number = 0 Then
            MsgBox "Save Successfully!"
        Else
            MsgBox Err.Number & ":" & Err.Description
        End If
      stream1.close
    -------------------------------------------------
      

  7.   

    我很菜!:(
    stream1是怎么定义 的啊 我找不到stream类啊
      

  8.   

    I have add:
    rst.addnew
    and now add new records to database!
    but the code:Sub ViewImage()
            stream1.Write rst.Fields("image1").Value
            stream1.SaveToFile App.Path & "\tmp.jpg", adSaveCreateOverWrite
            Image1.Picture = LoadPicture("" & App.Path & "\tmp.jpg")
    End Sub
    ______________________
    is still wrong!
    I cann't view image CONTINOUSLY!
      

  9.   

    我在相应的地方加上了Stream1.close还是有问题啊!就是我要显示下一张图片时,Image依然显示原先的图片,我rst.movefirst做了实验,还是显示同一张图片,但recordcount>1(无重复图片),错在什么地方啊?