Store OLE in Access

Results 1 to 9 of 9

Thread: Store OLE in Access

  1. #1
    Rude Jake Guest

    Default Store OLE in Access

    Does anyone have an example of storing OLE objects in an access database? images, documents...<BR><BR>Assuming that I have the user upload the object using either the microsoft upload component or something like aspUpload, how do you transfer the contents? as binary?<BR><BR>anyone?

  2. #2
    iyyappan n iyer Guest

    Default image mgt

    1. first get image upload code from author:Phil Collignon. God bless him.<BR><BR>2. Use it to upload images.<BR><BR>3. Access is no good when handling images.<BR><BR>4. upload and store images in a folder and store url ti image in <BR>table.<BR><BR>for example: v store product image url in product table<BR>like: "/newcart/prodpics/Product234.gif"<BR><BR>6. to display image<BR>create rs<BR>get url into memvar<BR>use img tag to display image<BR>

  3. #3
    Rude Jake Guest

    Default RE: more than image mgt

    This method is more efficient than storing the actual binary image in the database, but suffers from scalability issues. In such a scenario, the Employee&#039s photos must be saved on the Web server or on a machine the Web server can access. If this database was to be replicated to several database servers, the physical files would also need to be replicated and their filenames and locations preserved. This would be a major headache! <BR><BR>Also I&#039m want to store other objects in the database, like MS word files, and zip files... the OLE container can hold any of these types.<BR><BR>I know how to get these items out and serve them using the Response.ContentType...<BR>I just want to know how to structure the SQL to insert these types of items...<BR>

  4. #4
    iyyappan n iyer Guest

    Default download this article and program

    article: "File Uploading with ASP and VBScript "<BR>author: Phil Collignon<BR>site:<BR><BR>u will find code to write image into table field

  5. #5
    Join Date
    Dec 1969

    Default RE: more than image mgt

    If you are worried about the images the just use the full path<BR>, then database replication won&#039t matter

  6. #6
    nimish shah Guest

    Default RE: download this article and program

    does that mean we have to store images as separate physical files on the server. can&#039t we insert the images into the table cell having an image datatype. if this question sounds naive, please excuse me, i&#039m a beginner and need guidance?

  7. #7
    iyyappan n iyer Guest

    Default my experiance

    i made a image management program and vb5 with access as backend and access was awful.<BR><BR>then again, u may find it easy.<BR><BR>this time around, for a e-shop, i store images in folder and it has worked without a problem.<BR><BR>my advice, store images in folder.<BR><BR>all the same there is nothing against, experimenting, try reading and writing image to/from a access table, using asp, and try the same by storing images in folders.<BR>do whatever u find easy.

  8. #8
    Rude Jake Guest

    Default RE: download this article and program

    nimish shah:<BR>The image data type is only available in SQL server not in Access.<BR><BR>And just so everyone knows, once again, i&#039m not just talking about images, but the potential to store any type of object in that OLE container... zip files, executeables..., etc.

  9. #9
    Rude Jake Guest

    Default Here's The Code...

    Many thanks to some of the brillant authors at ASP today for the research needed to pull this off.<BR><BR>Assuming This is your Form:<BR><BR><BR>&#060;B&#062;OLE file selection:&#060;/b&#062; <BR>&#060;FORM METHOD="Post" ENCTYPE="multipart/form-data" ACTION="oleInsertDB.asp"&#062;<BR>OLE OBJECT : &#060;INPUT TYPE="file" NAME="blob"&#062;<BR><BR>&#060;INPUT TYPE="submit" NAME="Enter"&#062;<BR>&#060;/FORM&#062;<BR><BR>This is the oleInsertDB.asp<BR>---------<BR>&#060;%<BR>&#039****************************** **********************************<BR>&#039This file is used to put an oleObjects into a DataBase<BR>&#039********************************* *******************************<BR>Response.Expire s=0<BR>Response.Buffer = TRUE<BR>Response.Clear<BR>byteCount = Request.TotalBytes<BR>RequestBin = Request.BinaryRead(byteCount)<BR><BR>Dim UploadRequest<BR>Set UploadRequest = CreateObject("Scripting.Dictionary")<BR><BR>BuildU ploadRequest RequestBin<BR><BR>other = UploadRequest.Item("other").Item("Value")<BR>conte ntType = UploadRequest.Item("blob").Item("ContentType")<BR> filepathname = UploadRequest.Item("blob").Item("FileName")<BR>fil ename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))<BR>value = UploadRequest.Item("blob").Item("Value")<BR><BR>&# 039 Connect to your database.<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>objConn .Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " & Server.MapPath("/oleObjects.mdb") & ";"<BR>Set objRs = Server.CreateObject("ADODB.Recordset")<BR><BR><BR> &#039Write to DB<BR>objRs.Open "SELECT * FROM oleTable", objConn,3,3<BR>objRs.AddNew<BR>OLEchunck = value & chrB(0)<BR>objRs.Fields("oleObject").AppendChunk OLEchunck &#039write the binary info<BR>objRs.Fields("contentType") = contentType &#039write the content type<BR>objRs.Update<BR>objRs.MoveLast<BR><BR><BR> &#039Display the content written to the database as a test to verify it worked<BR>&#039You can use this with Pictures, I wouldn&#039t recommend doing this with an executeable... ;)<BR>&#039read data from db<BR>Response.ContentType = objRs.Fields("ContentType")<BR>size = objRs.Fields("oleObject").ActualSize<BR>blob = objRs.Fields("oleObject").GetChunk(size)<BR>Respon se.BinaryWrite blob<BR><BR>objRs.Close<BR>objConn.Close<BR><BR>&# 039Build the upload request and figure out what content type is...<BR>Sub BuildUploadRequest(RequestBin)<BR><BR> &#039Get the boundary<BR> PosBeg = 1<BR> PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))<B R> boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)<BR> boundaryPos = InstrB(1,RequestBin,boundary)<BR> <BR> &#039Get all data inside the boundaries<BR> Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))<BR><BR> &#039Members variable of objects are put in a dictionary object<BR> Dim UploadControl<BR> Set UploadControl = CreateObject("Scripting.Dictionary")<BR><BR> &#039Get an object name<BR> Pos = InstrB(BoundaryPos,RequestBin,getByteString("Conte nt-Disposition"))<BR> Pos = InstrB(Pos,RequestBin,getByteString("name="))<BR> PosBeg = Pos+6<BR> PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))<B R> Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))<BR> PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filen ame="))<BR> PosBound = InstrB(PosEnd,RequestBin,boundary)<BR><BR> &#039Test if object is of file type<BR> If PosFile&#060;&#062;0 AND (PosFile&#060;PosBound) Then<BR><BR> &#039Get Filename, content-type and content of file<BR> PosBeg = PosFile + 10<BR> PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))<B R> FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))<BR><BR> &#039Add filename to dictionary object<BR> UploadControl.Add "FileName", FileName<BR> Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))<BR> PosBeg = Pos+14<BR> PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))<B R><BR> &#039Add content-type to dictionary object<BR> ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))<BR> UploadControl.Add "ContentType",ContentType<BR><BR> &#039Get content of object<BR> PosBeg = PosEnd+4<BR> PosEnd = InstrB(PosBeg,RequestBin,boundary)-2<BR> Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)<BR> Else<BR><BR> &#039Get content of object<BR> Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))<BR> PosBeg = Pos+4<BR> PosEnd = InstrB(PosBeg,RequestBin,boundary)-2<BR> Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))<BR><BR> End If<BR><BR> &#039Add content to dictionary object<BR> UploadControl.Add "Value" , Value <BR><BR> &#039Add dictionary object to main dictionary<BR> UploadRequest.Add name, UploadControl <BR><BR> &#039Loop to next object<BR> BoundaryPos=InstrB(BoundaryPos+LenB(boundary),Requ estBin,boundary)<BR> Loop<BR><BR>End Sub<BR><BR>&#039String to byte string conversion<BR>Function getByteString(StringStr)<BR> For i = 1 to Len(StringStr)<BR> char = Mid(StringStr,i,1)<BR> getByteString = getByteString & chrB(AscB(char))<BR> Next<BR>End Function<BR><BR>&#039Byte string to string conversion<BR>Function getString(StringBin)<BR> getString =""<BR> For intCount = 1 to LenB(StringBin)<BR> getString = getString & chr(AscB(MidB(StringBin,intCount,1))) <BR> Next<BR>End Function<BR>%&#062;<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts