|
- Private Sub CommandButton1_Click() '保存相片
- '引用Microsoft ActiveX Data Objects 2.x Library
- If strFile = False Or TextBox1.Text = "" Then Exit Sub
- Dim cnn As New ADODB.Connection
- Dim rs As New ADODB.Recordset
- Dim srm As New ADODB.Stream
- On Error GoTo ErrMsg
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.Path & "\档案.mdb"
- srm.Mode = adModeReadWrite
- srm.Type = adTypeBinary
- srm.Open
- srm.LoadFromFile strFile
- SQL = "select * from 档案 where 编号='" & TextBox1.Text & "'"
- rs.Open SQL, cnn, adOpenDynamic, adLockOptimistic
- If rs.RecordCount <= 0 Then
- rs.AddNew
- rs.Fields("编号").Value = TextBox1.Text
- End If
- rs.Fields("相片").Value = srm.Read()
- rs.Update
- MsgBox "相片已存入数据库", vbInformation
- rs.Close
- Set rs = Nothing
- Set srm = Nothing
- cnn.Close
- Set cnn = Nothing
- Exit Sub
- ErrMsg:
- MsgBox Err.Description, , "错误报告"
- End Sub
本附件是离任版主zhaogang1960写给论坛上一位朋友的(敬佩离任版主zhaogang1960),里面中的保存环节,相同编号不会覆盖原来的相片,而是新增加一个相同的编号,我将 If rs.RecordCount <= 0 Then 改为 If rs.RecordCount > 0 Then 时,相同编号是可以覆盖原来的相片,但无法增加新的编号。请各位老师帮忙修改一下,使得保存相片时,编号已存在的,覆盖原来的相片,编号不存在的,建立新的编号保存。谢谢!
|
|