Here's an example of reading a picture from a pub database in Microsoft SQL Server and displaying it:
The following is the sample source code: <%@ Import namespace= "System.Data.SqlClient"%> <%@ Import namespace= "System.Drawing"%> <%@ Import namespace= "System.Drawing.Imaging"%> <%@ Import namespace= "System.IO"%> <script language= "C #" runat= "Server" > void Page_Load (Object Sender, EventArgs E) { MemoryStream stream = new MemoryStream (); SqlConnection connection; Connection = new SqlConnection ("server=localhost;database=pubs;uid=sa;pwd="); try { Connection. Open (); SqlCommand command; Command = new SqlCommand ("Select logo from pub_info where pub_id=\ ' 0736\ '", connection); byte[] Image; Image = command. ExecuteScalar (); Stream. Write (image, 0, image. Length); Bitmap Imgbitmap; Imgbitmap = new Bitmap (stream); Response.ContentType = "Image/gif"; Imgbitmap. Save (Response.outputstream, imageformat.gif); } finally { Connection. Close (); Stream. Clse (); } }
</script> |