Database access pictures (only the records you learn are not guaranteed to be correct)

Source: Internet
Author: User

First step://Get the picture of the current selection this.pictureBox1.Image = Image.fromstream (This.openFileDialog1.OpenFile ());//Gets the path of the current picture, string path = OpenFileDialog1.FileName.ToString ()///Add a picture of the development path to the FileStream class FileStream fs = new FileStream (path, FileMode.Open, FileAccess.Read);//Instantiate BinaryReader object by FileStream object BinaryReader br = new BinaryReader (fs);// The FileStream class object is converted to a binary array byte[] Imgbytesin = br through the Readbytes () method of the BinaryReader class object. Readbytes (Convert.ToInt32 (fs. Length); second step://Add the picture to the database string sql= "insert into pic values (@pic)"; sqlparameter[] param = new sqlparameter[] {new SqlParameter ("@pic", Imgbytesin)};D bhelper.getexecutequery (sql, param); Step three://Take the picture out of the database string sql= "SELECT * from pic where id=0"; SqlDataReader reader = dbhelper.getexecutereader (sql, NULL); MemoryStream MSS = null;

Refer to the following three articles, if not there is nothing to say:
Http://www.cnblogs.com/insus/p/4620420.html
Http://www.cnblogs.com/insus/p/4623507.html
Http://www.cnblogs.com/insus/p/4632889.html

Database access pictures (only the records you have learned are not guaranteed to be correct)

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.