Storage and display of images to binary

Source: Internet
Author: User
Public byte [] getpicturedata (string ImagePath) {/*** // use the file stream to open the file based on the path of the image file, and save it as byte [] filestream FS = new filestream (ImagePath, filemode. open); // It Can Be Another overload method byte [] bydata = new byte [FS. length]; FS. read (bydata, 0, bydata. length); FS. close (); Return bydata;} private void inserinto () {string Path = This. textbox1.text; byte [] strem = getpicturedata (PATH); // write the image to the database string conn = @ "Data Source = .; initial catalog = test; user id = sa; Password = 123456 "; using (sqlconnection sqlconn = new sqlconnection (conn) {sqlcommand sqlcomm = new sqlcommand (); sqlconn. open (); sqlcomm. connection = sqlconn; sqlcomm. commandtext = "insert into tubian values ('1', @ image)"; sqlcomm. commandtype = commandtype. text; sqlcomm. parameters. add ("@ image", sqldbtype. image, strem. length ). value = strem; sqlcomm. executenonquery ();}}
 
Private void showimager () {string conn = @ "Data Source = .; initial catalog = test; user id = sa; Password = 123456 "; using (sqlconnection sqlconn = new sqlconnection (conn) {sqlcommand sqlcomm = new sqlcommand (); sqlconn. open (); sqlcomm. connection = sqlconn; sqlcomm. commandtext = "select top 1 * From tubian"; sqlcomm. commandtype = commandtype. text; using (sqldatareader DR = sqlcomm. executereader () {Dr. read (); // response. contenttype = Dr ["image"]. tostring (); response. contenttype = "image/JPEG"; response. binarywrite (byte []) Dr ["image"]) ;}}

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.