Results 1 to 9 of 9

Thread: OLE Object

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    OLE Object

    Hi All,

    Is it possible to open a file that is stored in a Access database (OLE Object),
    The file could be of any type?

    Thanks

    Loftty

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: OLE Object

    No. If it's stored in a database then it isn't strictly a file. It's a bunch of bytes, and you'll get those bytes from the database as a Byte array. If you wanted to open the content as a file in its native application you'd have to save it to disc first, which you could do quite easily. That's the sort of thing the Temp folder is for. That's exactly what a browser does when you choose to open a file directly from the Web: it downloads the bytes, saves a file in the Temp folder and then opens that. A well written application will ensure that the file is deleted afterwards, if at all possible.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: OLE Object

    Hi,

    Could you give me an example of how to do this please?

    Thanks

    Loftty

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: OLE Object

    Hmmm... now I look at your first post again I could be wrong, given that your database contains OLE objects rather than actual file contents. When you retrieve a value from the database what is its type? Is it a Byte array?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: OLE Object

    Hi,

    Yer it is a byte array

    Thanks Lofty

  6. #6
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    Re: OLE Object

    Hello,

    Since I'll ask the same question, I think I'll join this conversation, if u don't mind loftty... ^_^
    Suppose I save a picture file as an object field. How can I load the picture from that field ?

    Thanks,
    WJ

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: OLE Object

    Hi Wen,

    You can load the picture from a OLE field with something like this.

    Code:
    int PictureCol = 0; 
    
                    string strConnFromDataBaseName = Provider + DataBaseName + ";User ID=" + Username + ";Password=" + Password + ";");       
                    Connection cn = new OleDbConnection(strConnFromDataBaseName);
    
    
                    OleDbCommand cmd = new OleDbCommand("SELECT [Column Name] FROM [Table Name] " +
                     "WHERE [Condition]=30", cn);
    
                    cn.Open();
                    OleDbDataReader dr = cmd.ExecuteReader();
                    dr.Read();
                    Byte[] b = new Byte[(dr.GetBytes(PictureCol, 0, null, 0, int.MaxValue))];
                    dr.GetBytes(PictureCol, 0, b, 0, b.Length);
                    dr.Close();
                    cn.Close();
                   
                    System.Drawing.ImageConverter cvrt = new ImageConverter();
                    Image img = (Image)cvrt.ConvertFrom(b);
                    
                    //Do what you want with the image here
    Loftty

  8. #8
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    Re: OLE Object

    So, after putting the OLE object into "img" variable, I can use the var ?

    ~ WJ ~

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: OLE Object

    Yes you can use img.

    Loftty

Posting Permissions

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



Click Here to Expand Forum to Full Width