After a program is developed, you need to manage the personnel information, which contains photos. Generally, the information of this blob field is relatively difficult to handle. After it is sent to winform, picturebox is placed and bound with bindingsource, almost no code is required to modify or display the photo information. However, many detours have taken place in the implementation process.
Picturebox attribute settings: (databindings) set the image attribute to the corresponding photo field in the bindingsource of the person.
Note the update and insert command settings in the tableadapt bound to the bindingsource object. The parameter attribute of the photo field providertype is set to longvarbinary or varbinary and the length is 0.
Note: Do not use access to insert data into the photo field of MDB; otherwise, data cannot be displayed. Use your own program to insert photos.
The only thing that requires code writing is the Click Event of the picturebox control. You can click this control to load the photo file to the picturebox control, the rest are automatically handed over to vs (photo display, modification to database, etc ):
Openfiledialog openfile = new openfiledialog ();
String filename = "";
If (openfile. showdialog () = dialogresult. OK)
{
Filename = openfile. filename;
This. Photo. Image = image. fromfile (filename );
}
Because bindingnavigator and other binding controls are used, a lot of code is saved.