<%@ 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