Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim ts As ADODB.Recordset
Dim mystream As ADODB.Stream
Dim ws As String
Private Sub cmdclear_Click()
txtsurname = ""
txtmiddle = ""
txtfirst = ""
txtsud = ""
txtdep = ""
txtdiv = ""
txtcourse = ""
Set imgstud.Picture = Nothing
End Sub
Private Sub cmdfirst_Click()
rs.MoveFirst
mystream.Open
mystream.Write rs.Fields("Picture")
ws = "d:\image"
mystream.SaveToFile ws
imgstud.Picture = LoadPicture(ws)
Kill ws
txtsurname = rs!Surname
txtmiddle = rs!Middlename
txtfirst = rs!Firstname
txtsud = rs!Studentnumber
txtdep = rs!Department
txtdiv = rs!Division
txtcourse = rs!Course
mystream.Close
End Sub
Private Sub cmdlast_Click()
rs.MoveLast
mystream.Open
mystream.Write rs.Fields("Picture")
ws = "d:\image"
mystream.SaveToFile ws
imgstud.Picture = LoadPicture(ws)
Kill ws
txtsurname = rs!Surname
txtmiddle = rs!Middlename
txtfirst = rs!Firstname
txtsud = rs!Studentnumber
txtdep = rs!Department
txtdiv = rs!Division
txtcourse = rs!Course
mystream.Close
End Sub
Private Sub cmdload_Click()
cdial.ShowOpen
ws = cdial.FileName
imgstud.Picture = LoadPicture(ws)
End Sub
Private Sub cmdnext_Click()
rs.MoveNext
mystream.Open
mystream.Write rs.Fields("Picture")
ws = "d:\image"
mystream.SaveToFile ws
imgstud.Picture = LoadPicture(ws)
Kill ws
txtsurname = rs!Surname
txtmiddle = rs!Middlename
txtfirst = rs!Firstname
txtsud = rs!Studentnumber
txtdep = rs!Department
txtdiv = rs!Division
txtcourse = rs!Course
mystream.Close
End Sub
Private Sub cmdprev_Click()
rs.MovePrevious
mystream.Open
mystream.Write rs.Fields("Picture")
ws = "d:\image"
mystream.SaveToFile ws
imgstud.Picture = LoadPicture(ws)
Kill ws
txtsurname = rs!Surname
txtmiddle = rs!Middlename
txtfirst = rs!Firstname
txtsud = rs!Studentnumber
txtdep = rs!Department
txtdiv = rs!Division
txtcourse = rs!Course
mystream.Close
End Sub
Private Sub cmdsearch_Click()
Dim fs As ADODB.Recordset
Set fs = New ADODB.Recordset
fs.Open "select * from student where Surname='" & txtsurname & "'" _
& "xor Firstname='" & txtfirst & "' xor Studentnumber='" & txtsud & "' xor Department='" & txtdep & "'" _
& "xor Division='" & txtdiv & "' xor Course='" & txtcourse & "'", cn, adOpenKeyset, adLockOptimistic
On Error Resume Next
fs.MoveFirst
If fs!Surname = "" Then
MsgBox "No match found"
txtsurname = ""
txtmiddle = ""
txtfirst = ""
txtsud = ""
txtdep = ""
txtdiv = ""
txtcourse = ""
Set imgstud.Picture = Nothing
End If
mystream.Open
mystream.Write fs.Fields("Picture")
ws = "d:\image"
mystream.SaveToFile ws
imgstud.Picture = LoadPicture(ws)
Kill ws
txtsurname = fs!Surname
txtmiddle = fs!Middlename
txtfirst = fs!Firstname
txtsud = fs!Studentnumber
txtdep = fs!Department
txtdiv = fs!Division
txtcourse = fs!Course
fs.Close
mystream.Close
End Sub
Private Sub cmdview_Click()
Frame1.Visible = True
End Sub
Private Sub Command1_Click()
mystream.Open
mystream.LoadFromFile ws
ts.Open "select * from student where 1=0", cn, adOpenKeyset, adLockOptimistic
ts.AddNew
ts.Fields!Surname = txtsurname.Text
ts.Fields!Middlename = txtmiddle.Text
ts.Fields!Firstname = txtfirst.Text
ts.Fields!Studentnumber = txtsud.Text
ts.Fields!Course = txtcourse.Text
ts.Fields!Department = txtdep.Text
ts.Fields!Division = txtdiv.Text
ts.Fields!Picture = mystream.Read
ts.Update
MsgBox "record updated"
ts.Close
mystream.Close
End Sub
Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set ts = New ADODB.Recordset
Set mystream = New ADODB.Stream
cn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
& "SERVER=itunit;" _
& "DATABASE = LIBRARY;" _
& "UID = root;" _
& "PWD = edmond;" _
& "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384
cn.CursorLocation = adUseClient
cn.Open
mystream.Type = adTypeBinary
rs.Open "select * from student where 1=1", cn, adOpenKeyset, adLockOptimistic
End Sub