& Lt; % @ Page Language = & quot; C # & quot; % & gt; & lt; % @ Import Namespace = & quot; System. data. oleDb & quot; % & gt; & lt; % @ Import Namespace = & quot; System. data. sqlClient & quot; % & gt; & lt; script runat = & quot; server & quot; & gt; protected void Page_Load (object sender, EventArgs e) {//// create a database connection, SQL statement, and create a parameter // ACCESS the database using this annotation section // string strCnn = & quot; Provider = Microsoft. jet. OLEDB.4.0; Data Source = & quot; + Server. mapPath (& quot; Image2Access. mdb & quot;); // OleDbConnection myConnection = new OleDbConnection (strCnn); // OleDbCommand command = new OleDbCommand (& quot; select * from Person Where PersonID = & quot; + Request. queryString [& quot; id & quot;], myConnection); // myConnection. open (); // OleDbDataReader dr = command. executeReader (); // if (dr. read () // {// Response. clear (); // Response. addHeader (& quot; Content-Type & quot;, dr [& quot; PersonImageType & quot;]. toString (); // Response. binaryWrite (byte []) dr [& quot; PersonImage & quot;]); //} // dr. close (); // myConnection. dispose (); // construct a database connection, SQL statement, create the parameter string strCnn = & quot; Persist Security Info = False; User ID = sa; Password =; Initial Catalog = Book; server = (local); & quot; SqlConnection myConnection = new SqlConnection (strCnn); SqlCommand command = new SqlCommand (& quot; select * from UserPhoto Where id = & quot; + Request. queryString [& quot; id & quot;], myConnection); myConnection. open (); SqlDataReader dr = command. executeReader (); if (dr. read () {Response. clear (); Response. addHeader (& quot; Content-Type & quot;, dr [& quot; ContentType & quot;]. toString (); Response. binaryWrite (byte []) dr [& quot; Photo & quot;]);} dr. close (); myConnection. dispose () ;}& lt;/script & gt;
Create SQL data table statements
Create table [UserPhoto] ([id] [int] IDENTITY (1, 1) not null, [UserName] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS not null, [ContentType] [varchar] (50) 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] GO