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)