Public Sub SavePic(ByVal pPicPath As String)
Dim Rs As New ADODB.Recordset
dim adoCn As New ADODB.Connection
Dim bytPicData() As Byte
dim strCn As String
Open pPicPath For Binary As #1
ReDim bytPicData(LOF(1) - 1)
Get #1, , bytPicData()
Close #1
Option Explicit
Dim conn As ADODB.Connection
Dim Chunk() As Byte
Dim lngLengh As Long
Dim intChunks As Integer
Dim intFragment As Integer
Const ChunkSize = 1000
Const lngDataFile = 1
Private Sub Savepic()
Open "c:\YOU.gif" For Binary Access Read As lngDataFile
lngLengh = LOF(lngDataFile)
If lngLengh = 0 Then Close lngDataFile: Exit Sub
intChunks = lngLengh \ ChunkSize
intFragment = lngLengh Mod ChunkSize
'OpenData 打开数据库
Dim i As Integer
Dim rs As New ADODB.Recordset
Dim strQ As String
ReDim Chunk(intFragment)
Get lngDataFile, , Chunk()
rs.Fields("rs_photo1").AppendChunk Chunk()
ReDim Chunk(ChunkSize)
For i = 1 To intChunks
Get lngDataFile, , Chunk()
rs.Fields("rs_photo1").AppendChunk Chunk()
Next i
rs.Update
rs.Close
Close lngDataFile
Call ShowPic
End Sub
Public Sub ShowPic()
'OpenData 打开数据库
Dim i As Integer
Dim rs As New ADODB.Recordset
Dim strQ, filename As String
If rs.State = adStateOpen Then rs.Close
strQ = "Select * From [mydata]"
rs.Open strQ, conn, adOpenStatic, adLockOptimistic
If rs.EOF <> True Then
rs.MoveLast
Else
Exit Sub
End If
On Error Resume Next
Open "pictemp" For Binary Access Write As lngDataFile
lngLengh = rs.Fields("rs_photo1").ActualSize
intChunks = lngLengh \ ChunkSize
intFragment = lngLengh Mod ChunkSize
ReDim Chunk(intFragment)
Chunk() = rs.Fields("rs_photo1").GetChunk(intFragment)
Put lngDataFile, , Chunk()
For i = 1 To intChunks
ReDim Buffer(ChunkSize)
Chunk() = rs.Fields("rs_photo1").GetChunk(ChunkSize)
Put lngDataFile, , Chunk()
Next i
Close lngDataFile
filename = "pictemp"
Picture1.Picture = LoadPicture(filename)
Image1.Stretch = True
Image1.Picture = Picture1.Picture
Kill filename
End Sub
' Set connection properties.
cn.ConnectionTimeout = 25 ' Set the time out.
cn.Provider = "sqloledb" ' Specify the OLE DB provider.
cn.Properties("Data Source").Value = ServerName ' Set SQLOLEDB connection properties.
cn.Properties("Initial Catalog").Value = DBName ' Set SQLOLEDB connection properties.
cn.Properties("Integrated Security").Value = "SSPI" ' Set SQLOLEDB connection properties.
' Change mousepointer while trying to open database.
Screen.MousePointer = vbHourglass
' Open the database.
cn.Open
' Open the Recordset.
Set rs = New ADODB.Recordset
rs.Open "select * from Employees", cn, adOpenKeyset, adLockPessimistic
' Move to the first record and display the data.
rs.MoveFirst
FillDataFields
' Change mousepointer back to the default after open.
Screen.MousePointer = vbDefault
Exit Sub
ErrHandler:
' Change mousepointer back to the default after open.
Screen.MousePointer = vbDefault
' Display the error message.
MsgBox Err.Description, , "Error "