asp.net quick connect Access_ practical tips

Source: Internet
Author: User

We're all in a hurry, right?

1, determine the ASP.net document header statement : <%@ Page language= "C #"%>

2, reference Database statements:

<%@ import namespace= "System.Data"%>
<%@ import namespace= "System.Data.OleDb"%>

3. Establish a database : Data.mdb

4, JS code script statement writing:

<script runat= "Server" >
  //Insert page code here
  //
  void Page_Load () {
    string db=@ "database/ Data.mdb ";
    String connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" +server.mappath (db) + ";";
    String sqlcmd= "CREATE TABLE Ieb_webs (ID identity primary key,title varchar (255) Default Null)";
    OleDbConnection conn=new OleDbConnection (CONNSTR);
    Conn. Open ();
    OleDbCommand olecmd=new OleDbCommand (sqlcmd,conn);
    Olecmd.executenonquery ();   Execute SQL command
    Response.Write ("Data table setup complete!") ");
    }
    Conn. Close ();
    Conn=null;
    olecmd=null;
  }
</script>

5, the JS statement to write HTML text

 
 

6, the final complete code structure such as:

 <%@ Page language= "C #"%> <%@ import namespace= "System.Data"%> <%@
    RT namespace= "System.Data.OleDb"%> <script runat= "Server" >//Insert page code here//void Page_Load () {
    String db=@ "Database/data.mdb";
    String connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" +server.mappath (db) + ";";
    String sqlcmd= "CREATE TABLE Ieb_webs (ID identity primary key,title varchar (255) Default Null)";
    OleDbConnection conn=new OleDbConnection (CONNSTR); Conn.
    Open ();
    OleDbCommand olecmd=new OleDbCommand (sqlcmd,conn);   Olecmd.executenonquery (); Execute SQL command Response.Write ("Data table setup complete!")
    "); } conn.
    Close ();
    Conn=null;
  Olecmd=null; } </script>  
 

The above is a quick and easy way to connect to access asp.net, and I hope you can follow the steps I've shared to achieve asp.net connection to access.

Related Article

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.