// Upload the image file to the image
System. Drawing. Image img = System. Drawing. image. fromfile (fileimg. postedfile. filename );
// Save to memory in JPEG format
MS for system. Io. memorystream = New System. Io. memorystream ();
IMG. Save (MS, system. Drawing. imaging. imageformat. JPEG );
// Save to memory in JPEG format
MS for system. Io. memorystream = New System. Io. memorystream ();
IMG. Save (MS, system. Drawing. imaging. imageformat. JPEG );
Using (Sqlconnection con = New Sqlconnection ( " Data Source =. \ sqlexpress; attachdbfilename = | datadirectory | \ database. MDF; Integrated Security = true; user instance = true " ))
{
Sqlcommand cmd = New Sqlcommand ( " Spinsertimage " , Con );
Cmd. commandtype = Commandtype. storedprocedure;
Cmd. Parameters. Add ( " @ Imagebinary " , System. Data. sqldbtype. Image );
// Binary data of an image
Cmd. Parameters [ " @ Imagebinary " ]. Value = Ms. toarray ();
Con. open ();
Sqldatareader SDR = Cmd. executereader ();
Response. clearcontent ();
Response. contenttype = " Image/JPEG " ;
While (SDR. Read ())
{
//Read and display the binary data of the corresponding record
Response. binarywrite ((Byte[]) SDR [0]);
}
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.