LISTING 1: Sample VB Code That Inserts an Image into a Column /////////////////////////////////////// /// module1.bas /////////////////////// /////////////////////////////////////// Attribute VB_Name = "Module1" Sub main() On Error GoTo ErrHandler: Dim cn As ADODB.Connection Dim rsEmployees As ADODB.Recordset Dim strCnn As String Dim strEmployeeID As String Dim lngOffset As Long Dim lngPhotoSize As Long Dim varPhoto As Variant Dim varChunk As Variant Const conChunkSize = 100 ' Open a connection. Set cn = New ADODB.Connection strCnn = "Provider=sqloledb;" & _ "Data Source=;Initial Catalog=Northwind;User Id=sa;Password=; " cn.Open strCnn ' Open the pub_info table. Set rsEmployees = New ADODB.Recordset rsEmployees.CursorType = adOpenKeyset rsEmployees.LockType = adLockOptimistic rsEmployees.Open "Employees", cn, , , adCmdTable strEmployeeID = "2" ' Copy the photo to a variable in chunks. rsEmployees.Filter = "EmployeeID = '" & strEmployeeID & "'" lngPhotoSize = rsEmployees!Photo.ActualSize Do While lngOffset < lngPhotoSize varChunk = rsEmployees!Photo.GetChunk(conChunkSize) varPhoto = varPhoto & varChunk lngOffset = lngOffset + conChunkSize ' Add a new record, copying the photo in chunks. rsEmployees.AddNew rsEmployees!FirstName = "FirstName1" rsEmployees!LastName = "LastName1" lngOffset = 0 ' Reset offset. Do While lngOffset < lngPhotoSize varChunk = LeftB(RightB(varPhoto, lngPhotoSize - lngOffset), _ conChunkSize) rsEmployees!Photo.AppendChunk varChunk lngOffset = lngOffset + conChunkSize Loop rsEmployees.Update rsEmployees.Close cn.Close Exit Sub ErrHandler: ' Change mouse pointer back to the default after opening. Screen.MousePointer = vbDefault ' Display the error message. MsgBox Err.Description, , "Error " ' End the program. End End Sub /////////////////////////////////////////////// /// And now project1.vbp ////////////////////// /////////////////////////////////////////////// Type=Exe Reference=*\G{00020430-0000-0000-C000-000000000046} #2.0#0#..\..\..\..\..\WIN NT\System32\stdole2.tlb#OLE Automation Reference=*\G{00000206 -0000-0010-8000- 00AA006D2EA4}#2.6#0#..\..\..\..\..\Program Files\Common Files\ System\ADO\msado15.dll#Microsoft ActiveX Data Objects 2.6 Library Reference=*\G{00000300-0000-0010-8000- 00AA006D2EA4}#2.6#0#..\..\..\..\..\Program Files\Common Files\ System\ADO\msador15.dll#Microsoft ActiveX Data Objects Recordset 2.6 Library Module=Module1; Module1.bas Startup="Sub Main" HelpFile="" Command32="" Name="Project1" HelpContextID="0" CompatibleMode="0" MajorVer=1 MinorVer=0 RevisionVer=0 AutoIncrementVer=0 ServerSupportFiles=0 VersionCompanyName="Microsoft Corp." CompilationType=0 OptimizationType=0 FavorPentiumPro(tm)=0 CodeViewDebugInfo=0 NoAliasing=0 BoundsCheck=0 OverflowCheck=0 FlPointCheck=0 FDIVCheck=0 UnroundedFP=0 StartMode=0 Unattended=0 Retained=0 ThreadPerObject=0 MaxNumberOfThreads=1 [MS Transaction Server] AutoRefresh=1