Database Add Picture Path exception

Source: Internet
Author: User

Tools: SQLServer2012 Visual Studio 2013

Scenario: Add a photo to the PictureBox control and save it in the database

I wrote it like this.

An error occurred:

PS: (There is a type of image in the database, because if you store too many photos, it will increase the burden of the database, so save the path of the picture)

Workaround:

Reason: Because picturebox1.imagelocation is null

To modify the code:

if (picturebox1.image! = null)
{
if (picturebox1.imagelocation = = null)
{
paras. ADD (New SqlParameter ("@ photo", DBNull.Value));
}

else {
paras. ADD (New SqlParameter ("@ photo", picturebox1.imagelocation));
}
}
Else
{
MessageBox.Show ("Photo cannot be empty", "hint");
}

You should also save the path to the selected file

This.pictureBox1.Image = Image.FromFile (openfiledialog1.filename);
Picturebox1.imagelocation = @openFileDialog1. filename;//Note to have @

Results:

Database Add Picture Path exception

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: info-contact@alibabacloud.com 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.