Make sure your Sql Field value in your table is VarBinary(max) There is an easier way of coding inserting pictures, files .. into a Sql VarBinary(max) field .. however this code works for me ..
Code: Select all | Expand
// open file //
nHANDLE := FOpen( cFILE )
IF FERROR() <> 0
SAYING := "Error reading file "+cFILE+CHR(10)
SAYING += " "+STR(FERROR())+CHR(10)
MsgInfo( SAYING )
oDLG:END()
RETURN(.F.)
ENDIF
// get number of bytes in file
nBYTES := FSEEK( nHANDLE, 0,2 )
// pad the buffer nBytes+1
cBUFFER := SPACE(nBYTES+1)
FSeek( nHANDLE, 0, 0 )
nBytesRead := FRead( nHANDLE, @cBuffer, nBytes )
FClose( nHANDLE )
if nBytesRead != nBytes
SAYING := "nBytesRead = "+str(nBYTESREAD)+CHR(10)
SAYING += "nBytes = "+str(nBYTES)+CHR(10)
SAYING += "Error Reading Data"+chr(10)
MsgInfo( saying )
oDLG:END()
RETURN ( .F. )
endif
cEID := _GenEid()
IF cEID = "BOGUS"
oDlg:End()
RETURN(.F.)
ENDIF
nDateTime := dtoc(date())//+" "+time()
oRsCh:AddNew()
oRsCh:Fields("doceid"):Value := cEID
oRsCH:Fields("TFormEid"):Value := cPROJECTEID
oRsCh:Fields("DImport"):Value := nDateTime
oRsCh:Fields("importby"):Value := xLOGIN
oRsCh:Fields("datalen"):Value := nBYTES
oRsCh:Fields("filename"):Value := cFILENAME
oRsCh:Fields("notes"):AppendChunk( VTArrayWrapper():New( 17, cBUFFER ) ) // ----------- inserts into "Notes" field which is a VarBinary(Max)
oRsCh:Update()
Rao has a much simpler code to insert a document into a Sql Database .. the above always works for me .
Rick Lipkin