Access Database code
& Lt; % @ Page Language = & quot; C # & quot; EnableViewState = & quot; true & quot; % & gt; & lt; % @ Import Namespace = & quot; system. data. oleDb & quot; % & gt; & lt ;! DOCTYPE html PUBLIC & quot;-// W3C // dtd xhtml 1.0 Transitional // EN & quot; http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script Runat = & quot; server & quot; & gt; protected void button#click (object sender, EventArgs e) {System. IO. stream fileDataStream = FileUpload1.PostedFile. inputStream; if (fileDataStream. length & lt; 1) {Msg. text = & quot; select a file. & Quot; return ;}// get the file size int fileLength = FileUpload1.PostedFile. contentLength; // create an array byte [] fileData = new byte [fileLength]; // fill in the file stream to the array fileDataStream. read (fileData, 0, fileLength); // obtain the file type string fileType = FileUpload1.PostedFile. contentType; // create a database connection, SQL statement, and create the parameter string strCnn = & quot; Provider = Microsoft. jet. OLEDB.4.0; Data Source = & quot; + Server. mapPath (& quot; Image2Access. mdb & quot;); OleDbConnection myCon Nection = new OleDbConnection (strCnn); OleDbCommand command = new OleDbCommand (& quot; insert into Person (PersonName, PersonEmail, PersonSex, PersonImageType, PersonImage) & quot; + & quot; VALUES (@ PersonName, @ PersonEmail, @ PersonSex, @ PersonImageType, @ PersonImage) & quot;, myConnection); command. parameters. addWithValue (& quot; @ PersonName & quot;, TextBox1.Text); command. parameters. addWithValue (& quot; @ PersonEmail & quo T;, & quot; mengxianhui@dotnet.aspx.cc & quot;); command. parameters. addWithValue (& quot; @ paramPersonSex & quot;, & quot; male & quot;); command. parameters. addWithValue (& quot; @ PersonImageType & quot;, fileType); command. parameters. addWithValue (& quot; @ PersonImage & quot;, fileData); // open the connection and run the query myConnection. open (); command. executeNonQuery (); myConnection. close (); Response. redirect (Request. rawUrl);} protected void Page_Load (o Bject sender, EventArgs e) {if (! Page. isPostBack) {BindGrid () ;}} private void BindGrid () {string strCnn = & quot; Provider = Microsoft. jet. OLEDB.4.0; Data Source = & quot; + Server. mapPath (& quot; Image2Access. mdb & quot;); OleDbConnection myConnection = new OleDbConnection (strCnn); OleDbCommand myCommand = new OleDbCommand (& quot; SELECT * FROM Person & quot;, myConnection); try {myConnection. open (); GridView1.DataSource = myCommand. executeReader (System. Data. commandBehavior. closeConnection); GridView1.DataBind ();} catch (OleDbException SQLexc) {Response. write (& quot; error when extracting data: & quot; + SQLexc. toString () ;}} protected string FormatURL (object strArgument) {return & quot; ReadImage. aspx? Id = & quot; + strArgument. ToString () ;}& lt;/script & gt; & lt; html xmlns = & quot; http://www.w3.org/1999/xhtml"><pead Runat = & quot; server & quot; & gt; & lt; title & gt; upload files to the database & lt;/title & gt; & lt;/head & gt; & lt; body & gt; & lt; form id = & quot; MengXianhui & quot; runat = & quot; server & quot; & gt; & lt; asp: gridView ID = & quot; GridView1 & quot; runat = & quot; server & quot; AutoGenerateColumns = & quot; false & quot; & gt; & lt; Columns & gt; & lt; asp: TemplateField & gt; & lt; ItemTemplate & gt; & lt; % # Eval (& quot; PersonName & quot;) % & gt; & lt; /ItemTemplate & gt; & lt;/asp: TemplateField & gt; & lt; ItemTemplate & gt; & lt; % # Eval (& quot; PersonEmail & quot;) % & gt; & lt;/ItemTemplate & gt; & lt;/asp: TemplateField & gt; & lt; asp: templateField & gt; & lt; ItemTemplate & gt; & lt; % # Eval (& quot; PersonSex & quot;) % & gt; & lt;/ItemTemplate & gt; & lt;/asp: TemplateField & gt; & lt; ItemTemplate & gt; & lt; img src = & quot; & lt; % # FormatURL (Eval (& quot; PersonID & quot;) % & gt; & quot;/& gt; & lt;/ItemTemplate & gt; & lt;/asp: templateField & gt; & lt;/Columns & gt; & lt;/asp: GridView & gt; & lt; br/& gt; Name: & lt; asp: TextBox ID = & quot; TextBox1 & quot; runat = & quot; server & quot; & gt; & lt;/asp: TextBox & gt; & lt; br/& gt; Photo: & lt; asp: FileUpload ID = & quot; FileUpload1 & quot; runat = & quot; server & quot;/& gt; & lt; asp: button ID = & quot; btnUpload & quot; runat = & quot; server & quot; Text = & quot; upload & quot; OnClick = & quot; button#click & quot; & gt; & lt;/asp: Button & gt; & lt; p & gt; & lt; asp: Label ID = & quot; Msg & quot; runat = & quot; server & quot; ForeColor = & quot; Red & quot; & gt; & lt;/asp: Label & gt; & lt;/p & gt; & lt; /form & gt; & lt;/body & gt; & lt;/html & gt;