Advanced ASP Programming (Objective 1): creating database tables with DAO SQL
Source: Internet
Author: User
Are you satisfied with your own database design? Are you sure you don't want to deal with it? For example, creating a new database table, such as creating or modifying a field ...... Of course, these are the columns of the design database.
In this case, do you need to download the database to the local machine, open it, modify it, and upload it again? This is the case in -_-!
Now you can access the information about this. After all, the code function saves a lot of time for manual operations. But isn't code generated manually? Haha :)
1. Create the database file cnbruce. mdb (no table is designed)
Database creation code:
<%
Option Explicit
Dim databasename 'defines the database name
Databasename = "cnbruce. mdb" 'database name
Dim databasepath 'defines the database storage path
Databasepath = "e: cnbrucedatabase" 'absolute database path
Dim databasever 'defines the database version 2000 or 97
Databasever = "2000"
Function Createdfile (FilePath, FileName, Ver)
Dim cnbruce, dbver
Select case ver
Case "97"
Dbver = "3.51"
Case "2000"
Dbver = "4.0"
End select
If dbver <> "" then
Set cnbruce = Server. CreateObject ("ADOX. Catalog ")
Call cnbruce. Create ("Provider = Microsoft. Jet. OLEDB." & dbver & "; Data Source =" & filepath & filename)
End if
End Function
Call Createdfile (databasepath, databasename, databasever) 'to create a database
%>
Then, let's look at how to design and create a new database table.
2. Create the database connection file conn. asp
<%
Db_path = "cnbruce. mdb"
Set conn = Server. CreateObject ("ADODB. Connection ")
Connstr = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath (db_path)
Conn. Open connstr
%>
3. Create a new database table Program Page, addtable. asp
<! -- # Include file = "conn. asp" -->
<%
Set rs = Server. CreateObject ("ADODB. Recordset ")
SQL = "create table aboutme (id integer primary key, name text, Birthday datetime )"
Rs. Open SQL, conn, 2, 3
%>
The database table file has been created.
Create table aboutme (id integer primary key, name text, Birthday datetime)
Create a new table named aboutme, and design the fields including id (primary keyword), name (remarks), and Birthday (time and date)
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