'main_data设置成public数组
Private Sub command_Click()
CMD1.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks
CMD1.FileName = ""
'避免二次打开出错
CMD1.Filter = "图像文件|*.jpg;*.bmp;*.jpeg;*.png"
CMD1.ShowOpen '打开媒体文件
picture1.Picture = LoadPicture(CMD1.FileName)
Set Bag = New PropertyBag '图片更新
Bag.WriteProperty "Image", picture1.Picture'支持jpg,bmp等基本格式
ReDim buff(LenB(Bag.Contents))
buff = Bag.Contents
main_data(0)="图片1"'检索关键字
main_data(1) = buff
call main_add(data(0))'添加记录
call main_read(data(0))'读取记录
end sub
Public Function Main_add(name1) As Integer '
Dim rs1 As New Recordset
Dim buff() As Byte
cn.Open ConnStr
SqlStr = "select * from table1
where name='" & name1 & "'"
rs.Open SqlStr, cn, 1, 3
If rs.RecordCount = 0 Then '不含重复记录
rs.AddNew
For i = 0 To 1: rs.Fields(i) = main_data(i): Next i
rs.Update
Main_add = 0
Else
Main_add = 1
End If
rs.Close
cn.Close
End Function
Public Function main_Read(name1)
Dim buff() As Byte
If name1 = "" Then
MsgBox ("读取的关键字不存在")
Else
cn.Open ConnStr
SqlStr = "select * from table1 where name='" & name1 & "'"
rs.Open SqlStr, cn, 1, 1
If rs.EOF Then
MsgBox ("读取的记录不存在")
Else
Form1.Text1.Text = IIf(IsNull(rs.Fields(0), "", rs.Fields(0))
If Not IsNull(rs.Fields(1)) Then
buff = rs.Fields(1).Value
Set Bag = New PropertyBag
Bag.Contents = buff
Call Bag.WriteProperty("Image", buff)
Set Form1.picture1.Picture = Bag.ReadProperty("Image")
End If
End If
rs.Close
cn.Close
End If
End Function