Dim con As New ADODB.Connection
Dim rec As ADODB.Recordset
Private Sub c1_Click()
'p.Filter = "图片文件(*.jpg,*.bmp)|*.jpg;*.bmp"
p.ShowOpen
t3.Text = p.FileName
'i.Picture = LoadPicture(p.FileName)
End Sub
Private Sub c2_Click()
Dim pic() As Byte
Dim lngFile As Long
Set rec = New Recordset
rec.Open "select * from stu where 1<>1", con, adOpenDynamic, adLockOptimistic, -1
lngFile = FreeFile
Open t3.Text For Binary As #lngFile
ReDim pic(LOF(lngFile))
Get #lngFile, , pic
Close #lngFile
rec.AddNew
rec.Fields(0).Value = t1.Text
rec.Fields(1).Value = t2.Text
rec.Fields(2).Value = pic
rec.Update
rec.Close
i.Picture = LoadPicture("")
End Sub
Private Sub c3_Click()
Dim pic() As Byte
Set rec = New Recordset
rec.Open "select * from stu where stu_id='" & t1.Text & "'", con
t2.Text = rec.Fields(1).Value
ReDim pic(rec.Fields(2).ActualSize) '返回2进制图片的字节长度
pic = rec.Fields(2).Value
Open App.Path & "\" & t1.Text For Binary As #1
Put #1, , pic
Close #1
'Set i.Picture = LoadPicture(App.Path & "\" & t1.Text)
'MsgBox App.Path
'Kill (App.Path & "\" & t1.Text)
End Sub
Private Sub Form_Load()
Set con = New Connection
con.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=kkk;Data Source=."
End Sub