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")
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")
Image1.Picture = LoadPicture(""& App.Path & "\tmp.jpg") 试试看
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中吗?
请各位朋友多多发表自己的见解,有用、无用都可以!
先使用这句:
rst.AddNew
<>rst.AddNew????
否则打开文件会出现只读或占用。
-------------------------------------------
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
-------------------------------------------------
stream1是怎么定义 的啊 我找不到stream类啊
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!