Sample sharing using database to save pictures after uploading pictures

Source: Internet
Author: User

  This article mainly introduces the upload of pictures after the use of the database to save the picture example, the need for friends can refer to the following

  Code as follows: Httppostedfile upfile = File1.PostedFile; int filelenght = Upfile.contentlength; Decimal FileSize = filelenght/1024; if (filelenght = 0) {    divshowgverror.visible = true;     Lblshowgverror.text = "Please select Upload file";     return; } string strimagename = Upfile.filename; String strimagetype = Strimagename.substring (Strimagename.lastindexof (".")). ToLower (); if (Strimagetype!= ". jpg" && strimagetype!= ". jpeg" && strimagetype!= ". bmp" && Strimagetype!= ". png") {    divshowgverror.visible = true;     Lblshowgverror.text = "Please upload a picture of the following file format: jpg,jpeg,bmp,png ";     return; } if (FileSize > 2048) {    divshowgverror.visible = true;     Lblshowgverror.text = "Upload picture cannot be larger than 2M";     return; else {    byte[] Filebytearray = new Byte[filelenght];     Stream streamobject = Upfile.inputstream ;     Streamobject.read (filebytearray, 0, filelenght); &nBsp     Strnewleave = "INSERT INTO [Leave] ([id],[employeeno],[agentid],[leavetype],[startdate],[enddate],[ Hours],[leaver Eason],[reporttime],[reportid],[imagename],[imagedata]) ";     Strnewleave + = "VALUES (@LeaveNo, @EmpNo, @AgentName, @LeaType, @StartDate, @EndDate, @Hours, @Reason, GETDATE (), @Adm in, @ImageName, @Image) ";       Sqlpara = new sqlparameter[] {      New SqlParameter ("@LeaveNo", Strleano),   &nbs P New SqlParameter ("@EmpNo", Strempno),     new SqlParameter ("@AgentName", Stragentid),     NEW SqlParameter ("@LeaType", Strleatype),     new SqlParameter ("@StartDate", Strdatest),     NEW SqlParameter ("@EndDate", Strdateend),     new SqlParameter ("@Hours", strhours),     New SqlParameter ("@Reason", Strreason),     new SqlParameter ("@Admin", stradmin),     new SqlParameter ("@ImageName", Strimagename),     new SqlParameter ("@Image", Filebytearray)   };       Streamobject.close (); The     code is as follows: SQLHelper SQLH = new SQLHelper ();         String Strid = context. request["ID"];         byte[] MyData = new Byte[0];         String str = " select [ImageData] from [Leave] where [id]= '" + Strid + "]";         DataTable dt = sqlh.executequery (str, commandtype.text);         if (dt. Rows.Count > 0)         {MyData = (byte[]) dt. ROWS[0][0]; int arraysize = mydata.getupperbound (0);   context. Response.OutputStream.Write (MyData, 0, arraysize);        }    

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.