Private Sub Command1_Click()
CommonDialog1.Filter = "(jpg文件).jpg|*.jpg" '选择要读入的图片
CommonDialog1.ShowOpen
Dim str As New ADODB.Stream
Dim sql As String
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
str.Type = adTypeBinary
str.Open
str.LoadFromFile CommonDialog1.FileName
conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Persist Security Info=false;Data source=" & App.Path + "\pic.mdb"
rs.Open "select pic from info", conn, 1, 3
rs.AddNew
rs("pic") = str.Read '将图片读入到数据库
rs.Update
rs.Close
conn.Close
str.Close
End Sub
Private Sub Command2_Click() '显示图片按钮
Dim str As New ADODB.Stream
Dim sql As String
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Persist Security Info=false;Data source=" & App.Path + "\pic.mdb"
rs.Open "select pic from info", conn, 1, 1
rs.MoveLast
str.Mode = adModeReadWrite
str.Type = adTypeBinary
str.Open
str.Write rs("pic")
str.SaveToFile App.Path + "\test.jpg", adSaveCreateOverWrite '运行时会自动在目录下创立一个test.jpg空图片来存放要显示的图片
Image1.Picture = LoadPicture(App.Path + "\test.jpg")
End Sub