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"]) ;}}