Jan 31, 2012
I'm having a problem that I've spent all day researching to try and figure out. It seems that the 'Attachment' type in an Access 2007 DB file is stored as three seperate pieces of data in the one field. If you open up the Relationships view, you can see it in the table itself.
View 3 Replies
I'm trying to do a simple DVD movie database to keep track of everything I have, and who I've loaned things out to. I'm doing this in part to further my education in VB.NET and to figure out some of the things involved with interacting with databases. I haven't actually written any code yet, read on and you'll understand what's going on.
I've got an Attachment field setup in the database to hold a picture of the movie poster or DVD cover art or something like that to help identify the film, and I named it 'Art' of type 'Attachment' since that will hold an image. Looking at the table in Access I see that 'Art' is broken down into three entries: Art.FileData, Art.FileName, Art.FileType. I'd like to be able to pull the filename and file type and display those on the form, but we'll get to that later.
When I use a drag-n-drop gridview of the database into my blank VB form, the Art field just shows the filename, in my case it's 'screenshot.png' since I just dumped a screen shot in as a test. So, the gridview on the form will see the field and display the filename, which is fine. If I do another Windows form and drag-n-drop a Details View (instead of the grid view), and have the Art field in the table set to a PictureBox (in the Data Sources view, you can highlight a field and then designate it as text or picture
or date or whatever), I end up with a blank box instead of my image.
I haven't typed any code into any of the forms at this point. I'm still in the Designer trying to get the layout and stuff the way I want it, afterwhich I'll start adding buttons and methods and such to search for things, print out a nice list of the films in the database (with and without pictures) and be able to sort out a list of who I've loaned things to (like an overdue book list). But so far, by just dragging and dropping from the Data Sources into the form, Studio automatically creates the dataset and bindings and such to read from the database file, and I can see all of my test data *except* for the image in the PictureBox (it's just blank/empty).
So, if you want to see what's happening and sort this out, then you need to do the following:
1. Create an access database with a table, that table having at least one field of type 'Attachment'
2. put a picture/image into that field as a first entry
3. in Studio (or in my case Express), create a new project, which'll have a blank form in it by default
4. create your database connection by using the 'Add new data source...' wizard for your Access DB file
5. from the Data Sources, expand the table views and change the attachemnt field from the default of TextBox to a PictureBox (you may have to Customize the types to get PictureBox to show up)
6. drag and drop that whole table onto your form, which will automatically create form elements to display the data and stuff
7. Run it, you'll see the problem.
I have no idea what I need to look at or edit or change to get this PictureBox to display the image from the database. Like I said before, if I leave the type set to the default of TextBox in the Data Sources view, then the field will display the filename of the file stored in that field of the database. Having not typed any code yet, I have nothing that I've done that I can edit other than the automatically created stuff that Studio did when I dragged the table into the form.
Being completely unfamiliar with how VB.NET wants to talk to a database (SQL server, Access or otherwise) I decided to create this little program to learn how to do it. But I ran into this problem and need a little help. What I'm looking for is what I need to change in the bindingSource or TableAdapter or TableAdapterManager or BindingsNavigator or whatever resource is binding the fields on the form to the entries in the database so that the PictureBox will get the part of my 'Art' field that actually
holds the image, not the filename or the type. I don't know how to do that, and that's what I'm trying to learn. What I would like to know is how to both get the image to display in the PicutreBox and pull the filename for that image as well to display beneath it or something in the form.
And before someone starts complaining about writing the whole program for me, I must say this is one element of a large personal project and if you read my entire post here you'll see that there are many other elements that will eventually go with it. I just need some help getting this one thing to work. Multiple web searches and such point to a variety of different approaches, many of
which I've tried to implement but nothing has worked. I'd like to do this entirely in .NET with no other dependencies if at all possible, but some of what I've seen so far today suggests using Interop and other things to make this work, but those haven't panned out for me either as of yet. My ultimate goal with this whole program is to have one (albeit probably large) executable file that will encompass the entire program, and to have it all work. After that, then I'll look into things like creating my own modules
and DLL's and such to thin it out, but I'm not even close to that point yet.