4 个解决方案
#1
Dim StrPicTemp As String
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Private Sub Form_Load()
conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=MyDataBase;Data Source=MyService"
rs.Open "planemsg", conn, 3, adLockOptimistic, adCmdTable
End Sub
-----------------------
'保存图片到数据库
Private Sub Command1_Click()
' On Error GoTo err
Dim StmPic As ADODB.Stream
'保存你所选择的图像
Set StmPic = New ADODB.Stream
StmPic.Type = adTypeBinary '指定流是二进制类型
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
StmPic.Open '将数据获取到Stream对象中
StmPic.LoadFromFile (CommonDialog1.FileName) '将选择的图像加载到打开的StmPic中
rs.AddNew
rs("id") = "111" '连同id一起插入到表里
rs.Fields("img").Value = StmPic.Read '从StmPic对象中读取数据
rs.Update
StmPic.Close
Exit Sub
err:
MsgBox err.Description
End Sub
-----------------------------------------
'读出图片,并显示
Private Sub Command2_Click()
Dim StmPic As ADODB.Stream
' On Error GoTo err
'读取显示数据库中id为111的图像
Set rs = conn.Execute("select img from planemsg where id='111'")
StrPicTemp = "c:\temp.jpeg"
Set StmPic = New ADODB.Stream
With StmPic
.Type = adTypeBinary
.Open
.Write rs.Fields("img") '写入数据库中的数据至Stream中
.SaveToFile StrPicTemp, adSaveCreateOverWrite '将Stream中数据写入临时文件中
.Close
End With
Picture2.Picture = LoadPicture(StrPicTemp) '用Picture控件显示图像
Exit Sub
err:
MsgBox err.Description
End Sub
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Private Sub Form_Load()
conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=MyDataBase;Data Source=MyService"
rs.Open "planemsg", conn, 3, adLockOptimistic, adCmdTable
End Sub
-----------------------
'保存图片到数据库
Private Sub Command1_Click()
' On Error GoTo err
Dim StmPic As ADODB.Stream
'保存你所选择的图像
Set StmPic = New ADODB.Stream
StmPic.Type = adTypeBinary '指定流是二进制类型
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
StmPic.Open '将数据获取到Stream对象中
StmPic.LoadFromFile (CommonDialog1.FileName) '将选择的图像加载到打开的StmPic中
rs.AddNew
rs("id") = "111" '连同id一起插入到表里
rs.Fields("img").Value = StmPic.Read '从StmPic对象中读取数据
rs.Update
StmPic.Close
Exit Sub
err:
MsgBox err.Description
End Sub
-----------------------------------------
'读出图片,并显示
Private Sub Command2_Click()
Dim StmPic As ADODB.Stream
' On Error GoTo err
'读取显示数据库中id为111的图像
Set rs = conn.Execute("select img from planemsg where id='111'")
StrPicTemp = "c:\temp.jpeg"
Set StmPic = New ADODB.Stream
With StmPic
.Type = adTypeBinary
.Open
.Write rs.Fields("img") '写入数据库中的数据至Stream中
.SaveToFile StrPicTemp, adSaveCreateOverWrite '将Stream中数据写入临时文件中
.Close
End With
Picture2.Picture = LoadPicture(StrPicTemp) '用Picture控件显示图像
Exit Sub
err:
MsgBox err.Description
End Sub
#2
我告诉你大体流程 吧
先从数据库里面读出2进制文件,在d;盘上组合成一个jpg文件,然后在窗体上load这个图片!
先从数据库里面读出2进制文件,在d;盘上组合成一个jpg文件,然后在窗体上load这个图片!
#3
看看这个,保存任何文件的:
http://www.play78.com/blog/blogview.asp?logID=160&cateID=19
有sql版和acess版
http://www.play78.com/blog/blogview.asp?logID=160&cateID=19
有sql版和acess版
#4
用picturebox绑定
#1
Dim StrPicTemp As String
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Private Sub Form_Load()
conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=MyDataBase;Data Source=MyService"
rs.Open "planemsg", conn, 3, adLockOptimistic, adCmdTable
End Sub
-----------------------
'保存图片到数据库
Private Sub Command1_Click()
' On Error GoTo err
Dim StmPic As ADODB.Stream
'保存你所选择的图像
Set StmPic = New ADODB.Stream
StmPic.Type = adTypeBinary '指定流是二进制类型
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
StmPic.Open '将数据获取到Stream对象中
StmPic.LoadFromFile (CommonDialog1.FileName) '将选择的图像加载到打开的StmPic中
rs.AddNew
rs("id") = "111" '连同id一起插入到表里
rs.Fields("img").Value = StmPic.Read '从StmPic对象中读取数据
rs.Update
StmPic.Close
Exit Sub
err:
MsgBox err.Description
End Sub
-----------------------------------------
'读出图片,并显示
Private Sub Command2_Click()
Dim StmPic As ADODB.Stream
' On Error GoTo err
'读取显示数据库中id为111的图像
Set rs = conn.Execute("select img from planemsg where id='111'")
StrPicTemp = "c:\temp.jpeg"
Set StmPic = New ADODB.Stream
With StmPic
.Type = adTypeBinary
.Open
.Write rs.Fields("img") '写入数据库中的数据至Stream中
.SaveToFile StrPicTemp, adSaveCreateOverWrite '将Stream中数据写入临时文件中
.Close
End With
Picture2.Picture = LoadPicture(StrPicTemp) '用Picture控件显示图像
Exit Sub
err:
MsgBox err.Description
End Sub
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Private Sub Form_Load()
conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=MyDataBase;Data Source=MyService"
rs.Open "planemsg", conn, 3, adLockOptimistic, adCmdTable
End Sub
-----------------------
'保存图片到数据库
Private Sub Command1_Click()
' On Error GoTo err
Dim StmPic As ADODB.Stream
'保存你所选择的图像
Set StmPic = New ADODB.Stream
StmPic.Type = adTypeBinary '指定流是二进制类型
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
StmPic.Open '将数据获取到Stream对象中
StmPic.LoadFromFile (CommonDialog1.FileName) '将选择的图像加载到打开的StmPic中
rs.AddNew
rs("id") = "111" '连同id一起插入到表里
rs.Fields("img").Value = StmPic.Read '从StmPic对象中读取数据
rs.Update
StmPic.Close
Exit Sub
err:
MsgBox err.Description
End Sub
-----------------------------------------
'读出图片,并显示
Private Sub Command2_Click()
Dim StmPic As ADODB.Stream
' On Error GoTo err
'读取显示数据库中id为111的图像
Set rs = conn.Execute("select img from planemsg where id='111'")
StrPicTemp = "c:\temp.jpeg"
Set StmPic = New ADODB.Stream
With StmPic
.Type = adTypeBinary
.Open
.Write rs.Fields("img") '写入数据库中的数据至Stream中
.SaveToFile StrPicTemp, adSaveCreateOverWrite '将Stream中数据写入临时文件中
.Close
End With
Picture2.Picture = LoadPicture(StrPicTemp) '用Picture控件显示图像
Exit Sub
err:
MsgBox err.Description
End Sub
#2
我告诉你大体流程 吧
先从数据库里面读出2进制文件,在d;盘上组合成一个jpg文件,然后在窗体上load这个图片!
先从数据库里面读出2进制文件,在d;盘上组合成一个jpg文件,然后在窗体上load这个图片!
#3
看看这个,保存任何文件的:
http://www.play78.com/blog/blogview.asp?logID=160&cateID=19
有sql版和acess版
http://www.play78.com/blog/blogview.asp?logID=160&cateID=19
有sql版和acess版
#4
用picturebox绑定