Re: [TUT] VB6 MSAccess Sample using ADO (UPDATED V3 20100216) now with ADD and DataRe
sir question to your program.
Function WriteImageToDB(source As String, t As Recordset, sField As String)
jump po tau dito:
'Open the source file.
SourceFile = FreeFile
where did you get the FreeFile?; and
Const BlockSize = 32768?
what does it mean 32768? ito po ba ung size ng picture in pixel?;
and other one is FileData = String$(LeftOver, 32);
FileData = String$(BlockSize, 32)
sir what is the function of this and logic?
ito pa po:
FileLength = LOF(SourceFile)
If FileLength = 0 then
WriteImageToDB = 0
Exit Function
End If
tanong ko po kung ang filelength = 0 walang ira-write sa database? then exit function;
FileLength = LOF(SourceFile)
ung LOF po ba is Length Of File na ang value ay galing sa SourceFile, i imumultiply ung LOF sa value ng SourceFile, tama po ba?
thanks.
ssshhhh....
lahat ng sasabihin ko sayo ay nasa MSDN, Google or microsoft
everytime you open a file, the OS assigns a handle or file number.
Freefile = Function to get the first file number that is free, ayaw ko mag assign ng number dahil di ko naman alam kung free yung number na yun
yung mga tamad they open a file this way
SourceFile = 1 ' do you know kung may isang open file na gumagamit ng 1?
ako di ko alam and i dont care to know,
i just call Freefile to give me the first free file number, pwedeng 1 or 32768, i dont care.
if you are paying attention sa school, 32768 is the largest value of your integer.
in ADODB, you can not assign a binary data directly into a datafield then save, unsafe yun.
waht we do, the safest way, maski malaki or maliit na image yan, is to break up the file into CHUNKS
Const BlockSize = 32768 '32768bytes per chunks
we read the image/binary file 32768 bytes at a time then insert it into the field sa databse natin
so kung may 130kb ka na image
it will take 40 chunks + yung sobra,
pagdating sa database magdidkit lahat yung chunks
ImageField:
chunk1 + chunk2 + chunk3 + .......... + remainder (leftover)
actually pwede din naman na isaksak mo lahat yung image sa field
pero as i said this is the safest way to do it.
that code will not have any problem loading large images into the database dahil by chunks ang pag load nya.
FileLength = LOF(SourceFile)
get the length of the file, sa computation ng chunks to ginagamit
LOF("C:\Windows\Notepad.exe") = file size ng notepad
if you get the size, you know how to loop by chunks.
at pag ang file lenght ay ZERO, ano pa ang gagawin mo, wala naman laman yung file.
FileData = String$(BlockSize, 32)
String("x", 20) = "xxxxxxxxxxxxxxxxxxxx" 'get mo?
nag gawa lang ako ng container ng string 32characters long
as i said nsa MSDN or M$ or Google yan
i remember may comment din yung code