Use picturebox in winform to display and modify photos in the database

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.