EDN Admin
Well-known member
Im having a problem that Ive 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.<br/>
<br/>
Im trying to do a simple DVD movie database to keep track of everything I have, and who Ive loaned things out to. Im 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 havent
actually written any code yet, read on and youll understand whats going on.
Ive 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. Id like to be able to pull the filename and file type and display those on the form, but well get to that later.<br/>
<br/>
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 its 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 havent typed any code into any of the forms at this point. Im still in the Designer trying to get the layout and stuff the way I want it, afterwhich Ill 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 Ive 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 (its just blank/empty).<br/>
<br/>
So, if you want to see whats happening and sort this out, then you need to do the following:<br/>
1. Create an access database with a table, that table having at least one field of type Attachment
<br/>
2. put a picture/image into that field as a first entry<br/>
3. in Studio (or in my case Express), create a new project, whichll have a blank form in it by default<br/>
4. create your database connection by using the Add new data source... wizard for your Access DB file<br/>
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)<br/>
6. drag and drop that whole table onto your form, which will automatically create form elements to display the data and stuff<br/>
7. Run it, youll see the problem.<br/>
<br/>
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 Ive done that I can edit other than the automatically created stuff that Studio did when I dragged the table into the form.<br/>
<br/>
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 Im 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 dont know how to do that, and thats what Im 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<br/>
and if you read my entire post here youll 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 Ive tried to implement but nothing has worked. Id like to do this entirely in .NET with no other dependencies if at all possible, but some of what Ive seen so far today suggests using Interop and other things to make this work, but those havent 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 Ill look into things like creating my own modules
and DLLs and such to thin it out, but Im not even close to that point yet.
View the full article
see it in the table itself.<br/>
<br/>
Im trying to do a simple DVD movie database to keep track of everything I have, and who Ive loaned things out to. Im 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 havent
actually written any code yet, read on and youll understand whats going on.
Ive 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. Id like to be able to pull the filename and file type and display those on the form, but well get to that later.<br/>
<br/>
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 its 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 havent typed any code into any of the forms at this point. Im still in the Designer trying to get the layout and stuff the way I want it, afterwhich Ill 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 Ive 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 (its just blank/empty).<br/>
<br/>
So, if you want to see whats happening and sort this out, then you need to do the following:<br/>
1. Create an access database with a table, that table having at least one field of type Attachment
<br/>
2. put a picture/image into that field as a first entry<br/>
3. in Studio (or in my case Express), create a new project, whichll have a blank form in it by default<br/>
4. create your database connection by using the Add new data source... wizard for your Access DB file<br/>
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)<br/>
6. drag and drop that whole table onto your form, which will automatically create form elements to display the data and stuff<br/>
7. Run it, youll see the problem.<br/>
<br/>
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 Ive done that I can edit other than the automatically created stuff that Studio did when I dragged the table into the form.<br/>
<br/>
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 Im 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 dont know how to do that, and thats what Im 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<br/>
and if you read my entire post here youll 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 Ive tried to implement but nothing has worked. Id like to do this entirely in .NET with no other dependencies if at all possible, but some of what Ive seen so far today suggests using Interop and other things to make this work, but those havent 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 Ill look into things like creating my own modules
and DLLs and such to thin it out, but Im not even close to that point yet.
View the full article