003. Connect Access Database code

Source: Internet
Author: User

1. Code in the front-end aspx

1 <%@ Page Language="C #"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_default" %>2 3 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">4 5 <HTMLxmlns= "http://www.w3.org/1999/xhtml" >6 <HeadID= "Head1"runat= "Server">7     <title>Configure Access database connections</title>8 </Head>9 <Body>Ten     <formID= "Form1"runat= "Server"> One     <Div> A         &nbsp;</Div> -     </form> - </Body> the </HTML>

2. Code in the background. cs file

1 usingSystem;2 usingSystem.Collections.Generic;3 usingsystem.web;4 usingSystem.Web.UI;5 usingSystem.Web.UI.WebControls;6 usingSystem.Configuration;7 usingSystem.Data.OleDb;8 9  Public Partial class_default:system.web.ui.pageTen { One     protected voidPage_Load (Objectsender, EventArgs e) A     { -         stringCon_access = configurationmanager.appsettings["Accesscon"]. ToString ();//Get the database connection string in the configuration file -Response.Write ("aceess Database connection string:"+ con_access);//the output gets the database string information theOleDbConnection Ocon =NewOleDbConnection (configurationmanager.appsettings["Accesscon"]); -         Try -         { -Ocon.open ();//Open a database connection +Response.Write ("<script>alert (' successful connection ') </script>"); -Ocon.close ();//To close a database connection +         } A         Catch(Exception ex) at         { -Response.Write ("<script>alert ("+ ex. ToString () +") </script>"); -         } -     } -}

3. Part of the code in Web. config

1   </configSections>2   <appSettings>3     <add key="Accesscon  " value="provider=microsoft.jet.oledb.4.0;  Data source=| Datadirectory|db_access.mdb"/>4   </appSettings>5   < Connectionstrings/>

003. Connect Access Database code

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.