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.