asp.net display the picture code in the database

Source: Internet
Author: User

<%@ Page language=" c#" %> <%@ Import namespace=" system.data.oledb" %> <%@ Import namespace=" system.data.sqlclient" %> <script runat="server"> protected void Page_Load (object sender, EventArgs e) {////build database connections, SQL statements, create parameters//access database Use this comment section//string strcnn = & quot Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath ("Image2Access.mdb")//oledbconnection myconnection = new OleDbConnection (STRCNN) ; OleDbCommand command = new OleDbCommand ("select * from person Where PersonID =" + request.querystring[ "id"], myconnection); Myconnection.open (); OleDbDataReader dr = command. ExecuteReader (); if (Dr. Read ())//{//Response.Clear ();//Response.AddHeader (" Content-type" a dr[". Personimagetype"]. ToString ()); Response.BinaryWrite ((byte[]) Dr[" Personimage"]); }//dr. Close (); Myconnection.dispose (); Building database connections, SQL statements, creating parameters string strcnn = " Persist Security Info=false; User Id=sa; Password=;initial Catalog=book; server= (local);"; SqlConnection myconnection = new SqlConnection (STRCNN); SqlCommand command = new SqlCommand ("select * from Userphoto Where ID =" + request.querystring[&quot ; id"], myconnection); Myconnection.open (); SqlDataReader dr = command. ExecuteReader (); if (Dr. Read ()) {response.clear (); Response.AddHeader (" Content-type" a dr[". Contenttype"]. ToString ()); Response.BinaryWrite ((byte[]) dr[" Photo"]); } Dr. Close (); Myconnection.dispose (); } </script>

To create a SQL data table statement

<xmp>CREATE TABLE [Userphoto] ([ID] [int] IDENTITY (1, 1) not NULL, [UserName] [nvarchar] (255) COLLATE Chinese_prc_ci_ As NOT NULL, [ContentType] [varchar] (m) COLLATE chinese_prc_ci_as not NULL, [Photo] [image] NOT NULL, CONSTRAINT [pk_ Userphoto] PRIMARY KEY CLUSTERED ([id]) on [PRIMARY]) on [PRIMARY] textimage_on [PRIMARY]</xmp> Go

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.