主题:学籍管理系统照片管理
现在我正在设计学籍管理系统,遇到一个问题就是学生照片的管理
我有一个窗体是显示学生信息的,有"首记录",“下一条","上一条"等按钮
我需要学生的照片随着学生记录的变化也随之变化,请问该怎么做
数据库用的access,其中有一student表里有照片的字段,类型是OLE,已经把照片存入这个字段记录中,VB中用的数据控件的image1
现在的代码如下:
Private Sub Form_Load()
MakeCenter FrmView
Set rs = cn.Execute("SELECT 课程名称 FROM course")
rs.MoveFirst
Do
CouNameCombo.AddItem rs.Fields(0).Value
rs.MoveNext
Loop Until rs.EOF
GradeRefresh
s_SaveFile
s_ReadFile
End Sub
Sub s_ReadFile()
Dim iStm As ADODB.Stream
Dim iRe As ADODB.Recordset
'打开表
Set iRe = New ADODB.Recordset
'得到最新添加的纪录
iRe.Open "select top 1 照片 from student order by 学号", cn, adOpenKeyset, adLockReadOnly
'保存到文件
Set iStm = New ADODB.Stream
With iStm
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write iRe("照片")
'这里注意了,如果当前目录下存在tmp.jpg,会报一个文件写入失败的错误.
.SaveToFile App.path & "\photo\tmp.jpg"
End With
Image1.Picture = LoadPicture(App.path & "\photo\tmp.jpg")
'关闭对象
iRe.Close
iStm.Close
End Sub
Sub s_SaveFile()
Dim iStm As ADODB.Stream
Dim iRe As ADODB.Recordset
Dim iConcstr As String
'读取文件到内容
Set iStm = New ADODB.Stream
With iStm
.Type = adTypeBinary '二进制模式
.Open
.LoadFromFile App.path + "\photo\1.jpg"
End With
'打开保存文件的表
Set iRe = New ADODB.Recordset
With iRe
.Open "select * from student", cn, 1, 3
'.AddNew '新增一条记录
.Fields("照片") = iStm.Read
.Update
End With
'完成后关闭对象
iRe.Close
iStm.Close
End Sub
我有一个窗体是显示学生信息的,有"首记录",“下一条","上一条"等按钮
我需要学生的照片随着学生记录的变化也随之变化,请问该怎么做
数据库用的access,其中有一student表里有照片的字段,类型是OLE,已经把照片存入这个字段记录中,VB中用的数据控件的image1
现在的代码如下:
Private Sub Form_Load()
MakeCenter FrmView
Set rs = cn.Execute("SELECT 课程名称 FROM course")
rs.MoveFirst
Do
CouNameCombo.AddItem rs.Fields(0).Value
rs.MoveNext
Loop Until rs.EOF
GradeRefresh
s_SaveFile
s_ReadFile
End Sub
Sub s_ReadFile()
Dim iStm As ADODB.Stream
Dim iRe As ADODB.Recordset
'打开表
Set iRe = New ADODB.Recordset
'得到最新添加的纪录
iRe.Open "select top 1 照片 from student order by 学号", cn, adOpenKeyset, adLockReadOnly
'保存到文件
Set iStm = New ADODB.Stream
With iStm
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write iRe("照片")
'这里注意了,如果当前目录下存在tmp.jpg,会报一个文件写入失败的错误.
.SaveToFile App.path & "\photo\tmp.jpg"
End With
Image1.Picture = LoadPicture(App.path & "\photo\tmp.jpg")
'关闭对象
iRe.Close
iStm.Close
End Sub
Sub s_SaveFile()
Dim iStm As ADODB.Stream
Dim iRe As ADODB.Recordset
Dim iConcstr As String
'读取文件到内容
Set iStm = New ADODB.Stream
With iStm
.Type = adTypeBinary '二进制模式
.Open
.LoadFromFile App.path + "\photo\1.jpg"
End With
'打开保存文件的表
Set iRe = New ADODB.Recordset
With iRe
.Open "select * from student", cn, 1, 3
'.AddNew '新增一条记录
.Fields("照片") = iStm.Read
.Update
End With
'完成后关闭对象
iRe.Close
iStm.Close
End Sub